The continue statement is used to skip the current iteration of a loop and move directly to the next iteration. It does not exit the loop completely, but rather skips the remaining code in the current iteration and jumps back to the loop’s condition for the next iteration.
Syntax:
continue;
Note: It is typically used when a certain condition is met, and you want to skip the current iteration without exiting the loop.
Example:
#include <stdio.h>
int main() {
for (int i = 1; i <= 5; i++) {
if (i == 4) {
continue; // Skip the rest of the loop when i is 4
}
printf("%d\n", i);
}
return 0;
}
Output:
2
3
5
C Continue Statement – Interview Questions
Q 1: What is the continue statement in C?
Q 2: Where can continue be used?
Q 3: What is the difference between break and continue?
Q 4: Does continue work in switch statements?
Q 5: Why use continue in loops?
C Continue Statement – Objective Questions (MCQs)
Q1. What does the continue statement do in C?
Q2. Which of the following best describes where continue can be used?
Q3. What will be the output of this code?
for (int i = 1; i <= 5; i++) {
if (i == 3)
continue;
printf("%d ", i);
}
Q4. What happens when a continue statement is encountered in a while loop?
Q5. What is the difference between break and continue?