0
0
Javaprogramming~10 mins

Continue statement in Java - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Continue statement
Start Loop
Check Condition
Yes
Check Continue Condition
Skip Rest
Next Iteration
End Loop
The loop checks a condition each time. If the continue condition is true, it skips the rest of the loop body and moves to the next iteration.
Execution Sample
Java
for (int i = 1; i <= 5; i++) {
    if (i == 3) continue;
    System.out.println(i);
}
Print numbers 1 to 5, but skip printing 3 using continue.
Execution Table
IterationiCondition i <= 5Continue Condition i == 3ActionOutput
11truefalsePrint 11
22truefalsePrint 22
33truetrueSkip print, continue to next
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 reaches i=3?
At iteration 3 in the execution_table, the continue condition is true, so the loop skips the print statement and moves to the next iteration.
Does the continue statement stop the entire loop?
No, continue only skips the rest of the current iteration and proceeds with the next iteration, as shown in the execution_table at iteration 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of i when the continue statement is triggered?
A3
B2
C4
D5
💡 Hint
Check the 'Continue Condition i == 3' column in the execution_table.
At which iteration does the loop stop running according to the execution_table?
A5
B3
C6
D1
💡 Hint
Look at the last row where the condition i <= 5 becomes false.
If the continue condition was changed to i == 2, which number would be skipped in the output?
A1
B2
C3
D4
💡 Hint
Refer to how the continue condition affects skipping output in the execution_table.
Concept Snapshot
continue statement in Java:
- Used inside loops to skip the rest of current iteration
- Moves control to next iteration immediately
- Syntax: if(condition) continue;
- Does NOT exit the loop, just skips current iteration
- Useful to ignore specific cases without breaking loop
Full Transcript
This example shows a for loop from 1 to 5. When i equals 3, the continue statement runs. This skips printing 3 and moves to the next number. The loop prints 1, 2, 4, and 5. The continue statement only skips the current iteration, not the whole loop. The loop ends when i becomes 6 because the condition i <= 5 is false.