In C programming, the continue statement works like a break statement, instead of terminating the loop the continue statement skips the code in between and pass it to the next iteration in the loop.
continue statement Flowchart:
Syntax of continue statement:
1 | continue; |
In the for loop, continue statement skips the test condition and increment value of the variable to execute again and In the while and do…while loops, continue skips all the statements and program control goes to at the end of the loop for tests condition.
Example of continue statement in C Program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include <stdio.h> int main() { int i = 0; while (i < 10) { i++; //the 8th iteration is skipped if (i == 8) continue; printf("Value of i: %d\n", i); } } |
The output of continue statement.
1 2 3 4 5 6 7 8 9 | Value of i: 1 Value of i: 2 Value of i: 3 Value of i: 4 Value of i: 5 Value of i: 6 Value of i: 7 Value of i: 9 Value of i: 10 |