![]() |
VOOZH | about |
The continue statement in C is a jump statement used to skip the remaining statements of the current loop iteration and move directly to the next iteration of the loop. It can be used inside for, while, and do-while loops.
1 2 4 5
Explanation: The loop runs from 1 to 5 and print each number. We add the continue statement inside an if statement that checks if the number is 3 i.e. i == 3. If it is, continue is reached and printing of 3 is skipped.
The continue statement works as follows:
The flowchart of the continue can be constructed using the understanding of the continue we got from above.
1 3 5 7 9
Explanation: The condition checks if the number n is even and when it's true it skips to the next iteration which prevents the print statement from executing as the print statement is below the continue so when the continue is executed (for even numbers), no printing is done.
The continue statement will only work in a single loop at a time. So, in the case of nested loops, we can use the continue statement to skip the current iteration of the inner loop when using nested loops.
0 1 2 4 0 1 2 4 0 1 2 4
The continue skips the current iteration of the inner loop when it executes in the above program. As a result, the program is controlled by the inner loop update expression. In this way, 3 is never displayed in the output.