Challenge - 5 Problems
Break Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of break in nested loops
What is the output of this Python code?
for i in range(3):
for j in range(3):
if j == 1:
break
print(i, j)Python
for i in range(3): for j in range(3): if j == 1: break print(i, j)
Attempts:
2 left
💡 Hint
The break stops the inner loop when j equals 1, so only j=0 prints each time.
✗ Incorrect
The inner loop breaks when j == 1, so only j=0 prints for each i from 0 to 2.
❓ Predict Output
intermediate1:30remaining
Break effect on single loop
What will be printed by this code?
for x in range(5):
if x == 3:
break
print(x)Python
for x in range(5): if x == 3: break print(x)
Attempts:
2 left
💡 Hint
The loop stops completely when x equals 3.
✗ Incorrect
The break stops the loop when x == 3, so only 0,1,2 print.
❓ Predict Output
advanced2:00remaining
Break inside while loop with else
What is the output of this code?
i = 0
while i < 5:
if i == 3:
break
print(i)
i += 1
else:
print('Done')Python
i = 0 while i < 5: if i == 3: break print(i) i += 1 else: print('Done')
Attempts:
2 left
💡 Hint
The else block runs only if the loop completes without break.
✗ Incorrect
The break stops the loop at i==3, so else does not run. Only 0,1,2 print.
❓ Predict Output
advanced1:30remaining
Break with continue in loop
What will this code print?
for n in range(5):
if n == 2:
break
if n == 1:
continue
print(n)Python
for n in range(5): if n == 2: break if n == 1: continue print(n)
Attempts:
2 left
💡 Hint
Continue skips printing when n==1, break stops loop at n==2.
✗ Incorrect
At n=0 print 0, n=1 continue skips print, n=2 break stops loop. So only 0 prints.
🧠 Conceptual
expert1:30remaining
Break statement effect on loop else clause
Consider this code snippet:
What will be printed when this code runs?
for i in range(4):
if i == 5:
break
else:
print('Loop ended normally')What will be printed when this code runs?
Attempts:
2 left
💡 Hint
The break condition is never true, so loop completes normally.
✗ Incorrect
Since i never equals 5, break never runs. The else clause runs after normal loop completion.