0
0
C Sharp (C#)programming~10 mins

Continue statement behavior in C Sharp (C#) - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Continue statement behavior
Start Loop
Check Condition
Yes
Execute Loop Body
Is 'continue' reached?
YesSkip rest of body
Execute remaining body
Update Loop Variable
Repeat Loop
No
Exit Loop
The loop checks its condition, executes the body, and if 'continue' is reached, it skips the rest of the body and moves to the next iteration.
Execution Sample
C Sharp (C#)
for (int i = 0; i < 5; i++) {
    if (i == 2) continue;
    Console.Write(i + " ");
}
This code prints numbers 0 to 4, but skips printing 2 because of the continue statement.
Execution Table
Iterationi valueCondition (i<5)Continue Check (i==2)ActionOutput
10TrueFalsePrint 00
21TrueFalsePrint 11
32TrueTrueSkip print, continue to next iteration
43TrueFalsePrint 33
54TrueFalsePrint 44
65False-Exit loop
💡 i reaches 5, condition i<5 is False, loop ends
Variable Tracker
VariableStartAfter 1After 2After 3After 4After 5Final
i0123455
Key Moments - 2 Insights
Why does the number 2 not get printed even though the loop runs when i=2?
Because at iteration 3 (i=2), the condition i==2 is true, so the continue statement skips the print and moves to the next iteration, as shown in the execution_table row 3.
Does the continue statement stop the entire loop?
No, continue only skips the rest of the current loop iteration and proceeds to the next one, as seen in the execution_table where after continue, the loop variable updates and the loop continues.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the output after iteration 4?
A"0 1 3 "
B"0 1 2 3 "
C"0 1 3 4 "
D"0 1 2 3 4 "
💡 Hint
Check the Output column up to iteration 4 in the execution_table.
At which iteration does the loop stop running?
AAfter iteration 5
BAfter iteration 6
CAfter iteration 4
DAfter iteration 3
💡 Hint
Look at the exit_note and the Condition column in the execution_table.
If the continue statement was removed, what would be the output after iteration 3?
A"0 1 3 "
B"0 1 "
C"0 1 2 "
D"2 3 4 "
💡 Hint
Without continue, the print happens every iteration; check Output column for iterations before continue.
Concept Snapshot
continue statement in loops:
- When 'continue' runs, skip rest of current loop body
- Move immediately to next iteration
- Loop variable updates as usual
- Useful to skip specific cases without stopping loop
Full Transcript
This example shows how the continue statement works in a C# for loop. The loop runs from i=0 to i=4. When i equals 2, the continue statement skips printing that number and moves to the next iteration. The output prints 0, 1, 3, and 4, skipping 2. The loop ends when i reaches 5 and the condition i<5 becomes false. Continue does not stop the loop, it only skips the rest of the current iteration.