Please note that continue statement can be used only inside a loop statement.
In the following example, while loop tries to print numbers from 0 to 9. But during fourth iteration when i becomes 4, continue statement skips the execution of printing the number.
Refer C While Loop tutorial.
main.cpp
|
Output
|
Also, the control variable i
is not incremented because of the continue statement. So, we incremented i
before executing the continue statement. If i
not modified here, the while loop may become indefinite loop.
In the following example, do-while loop tries to print numbers from 0 to 9. But during fifth iteration when i
becomes 5
, continue statement skips the execution of further statements in the loop.
Refer C Do-while Loop tutorial.
main.cpp
|