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:
1
2
3
5
2
3
5