0
0
C++programming~10 mins

Continue statement in C++ - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Continue statement
Start loop iteration
Check condition
Yes
Check if continue condition
Yes|No
Skip rest of loop
Next iteration or exit
The loop checks a condition each iteration. If the continue condition is true, it skips the rest of the loop body and moves to the next iteration.
Execution Sample
C++
for (int i = 1; i <= 5; i++) {
    if (i == 3) continue;
    std::cout << i << " ";
}
Print numbers 1 to 5 but skip printing 3 using continue.
Execution Table
IterationiCondition i <= 5Check if i == 3ActionOutput
11TrueFalsePrint 11
22TrueFalsePrint 22
33TrueTrueContinue (skip print)
44TrueFalsePrint 44
55TrueFalsePrint 55
66False-Exit loop
💡 i reaches 6, condition i <= 5 is False, loop ends
Variable Tracker
VariableStartAfter 1After 2After 3After 4After 5Final
i1234566
Key Moments - 2 Insights
Why does the number 3 not get printed even though the loop runs when i is 3?
At iteration 3 in the execution_table, the condition i == 3 is True, so the continue statement skips the print action and moves to the next iteration.
Does the continue statement stop the entire loop?
No, continue only skips the rest of the current iteration. The loop continues with the next iteration as shown in rows 3 and 4 of the execution_table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the output after iteration 2?
A"1 2 3 "
B"2 "
C"1 2 "
D""
💡 Hint
Check the Output column after iteration 2 in the execution_table.
At which iteration does the continue statement cause the loop to skip printing?
AIteration 3
BIteration 1
CIteration 5
DIteration 6
💡 Hint
Look at the 'Check if i == 3' and 'Action' columns in the execution_table.
If the continue statement was removed, what would be the output after iteration 5?
A"3 "
B"1 2 3 4 5 "
C"1 2 4 5 "
D""
💡 Hint
Without continue, the print happens every iteration where i <= 5.
Concept Snapshot
continue statement in C++:
- Used inside loops to skip the rest of current iteration
- Control jumps to next iteration immediately
- Syntax: if(condition) continue;
- Useful to skip specific cases without breaking the loop
- Loop continues until its main condition fails
Full Transcript
This example shows a for loop from 1 to 5. Each time, it checks if i equals 3. If yes, continue skips printing 3 and moves to next iteration. Otherwise, it prints the number. The loop ends when i becomes 6 because the condition i <= 5 is false. The continue statement only skips the current iteration's remaining code, not the whole loop.