0
0
Pythonprogramming~20 mins

Break statement behavior in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Break Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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)
A
0 0
0 1
1 0
1 1
2 0
2 1
B
0 0
1 0
2 0
0 1
1 1
2 1
C
0 0
1 0
2 0
D
0 0
1 0
2 0
0 1
1 1
2 1
0 2
1 2
2 2
Attempts:
2 left
💡 Hint
The break stops the inner loop when j equals 1, so only j=0 prints each time.
Predict Output
intermediate
1: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)
A
0
1
2
B
0
1
2
3
C
0
1
2
3
4
D
3
4
Attempts:
2 left
💡 Hint
The loop stops completely when x equals 3.
Predict Output
advanced
2: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')
A
0
1
2
Done
B
0
1
2
CDone
D
0
1
2
3
Attempts:
2 left
💡 Hint
The else block runs only if the loop completes without break.
Predict Output
advanced
1: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)
A
0
2
B
0
1
C
0
1
2
D0
Attempts:
2 left
💡 Hint
Continue skips printing when n==1, break stops loop at n==2.
🧠 Conceptual
expert
1:30remaining
Break statement effect on loop else clause
Consider this code snippet:
for i in range(4):
    if i == 5:
        break
else:
    print('Loop ended normally')

What will be printed when this code runs?
ALoop ended normally
BNo output
CSyntaxError
DRuntimeError
Attempts:
2 left
💡 Hint
The break condition is never true, so loop completes normally.