0
0
Goprogramming~5 mins

Loop execution flow in Go - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the basic structure of a for loop in Go?
A for loop in Go has three parts: initialization, condition, and post statement. It looks like:
for i := 0; i < 5; i++ { /* code */ }
Click to reveal answer
beginner
What happens when the condition in a Go for loop becomes false?
The loop stops executing and the program continues with the code after the loop.
Click to reveal answer
intermediate
How does the continue statement affect loop execution in Go?
The continue statement skips the rest of the current loop iteration and moves to the next iteration immediately.
Click to reveal answer
intermediate
What does the break statement do inside a Go loop?
The break statement immediately exits the loop, skipping any remaining iterations.
Click to reveal answer
intermediate
Can a Go for loop run forever? How?
Yes. If the loop condition is omitted or always true, the loop runs forever. Example:
for { /* infinite loop */ }
Click to reveal answer
What part of the Go for loop controls how many times it runs?
AThe condition expression
BThe initialization statement
CThe post statement
DThe loop body
What does the continue statement do inside a Go loop?
AStops the loop completely
BSkips to the next iteration
CRestarts the program
DExits the current function
Which statement immediately exits a Go loop?
Acontinue
Bexit
Cbreak
Dstop
What happens if you omit the condition in a Go for loop?
AThe loop runs forever
BThe loop runs once
CThe loop runs zero times
DThe code will not compile
In Go, which part of the for loop runs after each iteration?
AInitialization
BCondition
CLoop body
DPost statement
Explain how the flow of execution works in a Go for loop from start to finish.
Think about the order of the three parts and when the loop body runs.
You got /5 concepts.
    Describe the difference between break and continue statements in Go loops.
    One stops the loop, the other skips to the next round.
    You got /4 concepts.