Recall & Review
beginner
What does the
break statement do in a loop?The
break statement immediately stops the loop and exits it, skipping any remaining iterations.Click to reveal answer
beginner
Can
break be used outside of loops?No, the
break statement can only be used inside loops like for or while. Using it outside causes an error.Click to reveal answer
intermediate
What happens if
break is inside nested loops?The
break statement only exits the innermost loop where it is used, not all loops.Click to reveal answer
beginner
Example: What will this code print?<br>
for i in range(5):
if i == 3:
break
print(i)It will print:<br>0<br>1<br>2<br>When
i becomes 3, the break stops the loop immediately.Click to reveal answer
intermediate
Why use
break instead of a condition in the loop?Using
break can make code clearer by stopping the loop exactly when needed, instead of adding complex conditions to the loop header.Click to reveal answer
What does the
break statement do inside a loop?✗ Incorrect
The
break statement stops the loop immediately and exits it.Where can you use the
break statement?✗ Incorrect
break is valid only inside loops like for or while.If
break is inside nested loops, which loop does it stop?✗ Incorrect
break stops only the innermost loop where it is used.What will this code print?<br>
for i in range(3):
if i == 1:
break
print(i)✗ Incorrect
When
i is 1, break stops the loop, so only 0 is printed.Why might you choose
break over a loop condition?✗ Incorrect
break lets you stop the loop exactly at the right moment inside the loop body.Explain how the
break statement affects loop execution.Think about what happens when you want to stop a repeated task early.
You got /3 concepts.
Describe the behavior of
break inside nested loops.Imagine loops inside loops and which one stops.
You got /3 concepts.