0
0
Goprogramming~10 mins

Continue statement in Go - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Continue statement
Start Loop
Check Condition
Yes
Check if continue condition
Skip rest of loop
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
Go
for i := 1; i <= 5; i++ {
    if i == 3 {
        continue
    }
    fmt.Println(i)
}
This loop prints numbers 1 to 5 but skips printing 3 using continue.
Execution Table
Iterationi valueCondition i == 3?ActionOutput
11NoPrint 11
22NoPrint 22
33YesContinue (skip print)
44NoPrint 44
55NoPrint 55
66Loop endsExit 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 i reaches 3?
Because at iteration 3, the condition i == 3 is true, so the continue statement skips the print action as shown in execution_table row 3.
Does the continue statement stop the entire loop?
No, continue only skips the rest of the current loop iteration and moves to the next one, as seen in execution_table rows 3 and 4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the output at iteration 3?
A3
BNo output
CError
D0
💡 Hint
Check the 'Output' column for iteration 3 in the execution_table.
At which iteration does the loop stop running?
A6
B3
C5
D1
💡 Hint
Look at the exit_note and the last row in execution_table.
If we remove the continue statement, what will happen at iteration 3?
ALoop will break
BNothing changes
C3 will be printed
DLoop will skip iteration 4
💡 Hint
Refer to the action and output difference in execution_table row 3.
Concept Snapshot
Go continue statement:
- Used inside loops to skip current iteration
- Syntax: continue
- When hit, skips rest of loop body
- Loop continues with next iteration
- Useful to ignore specific cases without breaking loop
Full Transcript
This example shows a Go for loop from 1 to 5. Each time, it checks if the current number i equals 3. If yes, the continue statement skips printing that number and moves to the next loop cycle. Otherwise, it prints the number. The loop stops when i becomes 6 because the condition i <= 5 is false. The continue statement only skips the current iteration, not the whole loop.