Challenge - 5 Problems
Loop Control Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of break in a loop
What is the output of this Python code using
break inside a loop?Python
for i in range(5): if i == 3: break print(i)
Attempts:
2 left
💡 Hint
Remember,
break stops the loop immediately when the condition is met.✗ Incorrect
The loop prints numbers from 0 up to but not including 3. When i == 3, the break stops the loop, so 3 is not printed.
❓ Predict Output
intermediate2:00remaining
Output of continue in a loop
What is the output of this Python code using
continue inside a loop?Python
for i in range(5): if i == 3: continue print(i)
Attempts:
2 left
💡 Hint
Think about what
continue does: it skips the current loop iteration.✗ Incorrect
The loop prints numbers from 0 to 4 but skips printing 3 because continue skips the rest of the loop body when i == 3.
🧠 Conceptual
advanced1:30remaining
Difference between break and continue
Which statement correctly describes the difference between
break and continue in loops?Attempts:
2 left
💡 Hint
Think about what happens to the loop after each keyword is executed.
✗ Incorrect
break stops the whole loop immediately. continue skips the rest of the current loop cycle and moves to the next one.
❓ Predict Output
advanced2:00remaining
Loop behavior with break and continue combined
What is the output of this code that uses both
break and continue?Python
for i in range(6): if i == 2: continue if i == 4: break print(i)
Attempts:
2 left
💡 Hint
Check the order of conditions and what each keyword does.
✗ Incorrect
When i == 2, continue skips printing 2. When i == 4, break stops the loop. So printed numbers are 0, 1, and 3.
🧠 Conceptual
expert2:30remaining
Effect of break and continue in nested loops
In nested loops, which statement is true about
break and continue?Attempts:
2 left
💡 Hint
Think about which loop the keywords apply to when loops are inside each other.
✗ Incorrect
Both break and continue affect only the loop they are directly inside, usually the innermost loop.