![]() |
VOOZH | about |
The continue statement in C++ is a loop control statement that skips the remaining statements of the current iteration and immediately transfers control to the next iteration of the loop.
1 2 3 5 6 7 8 9 10
Explanation: When i becomes 4, the continue statement skips the cout statement and immediately starts the next iteration. Therefore, 4 is not printed.
continue;
The continue statement can only be used inside loops. When encountered, it skips the remaining statements of the current iteration and proceeds to the next iteration.
The working of the continue statement is as follows:
The continue statement can be used with all looping constructs in C++, but the point at which control moves to the next iteration differs for each loop type.
In a while loop, control returns directly to the condition check after encountering continue.
1 2 3 5 6 7 8 9 10
Explanation: When i becomes 4, the remaining statements of that iteration are skipped and the loop continues with the next value.
Note: In while loops, update the loop variable before continue; otherwise, the loop may become infinite.
In a do-while loop, continue transfers control directly to the condition check.
1 2 3 5 6 7 8 9 10
Explanation: The value 4 is skipped because continue is executed before the print statement.
Note: In while and do-while loop, we updated the loop variable i before the continue statement or else we will keep encountering continue before updating the loop variable creating an infinite loop.
When used inside nested loops, continue affects only the loop in which it appears.
0 1 3 4 0 1 3 4
Explanation: The continue statement skips the iteration where j equals 2, so that value is never printed.