Sharpen your Python skills with multiple-choice questions on loop control statements. Practice break, continue, and else with real coding scenarios.
Topic: loop-control-statements
for i in range(5):
    if i == 3:
        continue
    print(i)
0 1 2 4
The continue statement skips iteration when i==3, so 3 is not printed.
for i in range(5):
    if i == 3:
        break
    print(i)
0 1 2
The break statement exits the loop completely when i==3.
i = 0
while i < 5:
    i += 1
    if i == 3:
        break
    print(i)
else:
    print("Loop completed")
1 2
The break exits the loop before completion, so the else clause doesn't execute.
Exits the loop immediately
The break statement exits the entire loop structure regardless of the loop condition.
Exits the loop immediately
The break statement exits the entire loop structure regardless of the loop condition.
for char in "Python":
    if char == 'h':
        break
    print(char, end='')
Pyt
The loop breaks when it encounters 'h'.
break
The break statement exits the nearest enclosing loop.
x = 5
while x > 0:
    x -= 1
    if x == 2:
        continue
    print(x, end=' ')
4 3 1 0
The continue skips printing when x is 2, and the loop stops when x reaches 0.
x = 0
for i in range(5):
    if i % 2 == 0:
        continue
    x += i
4
Only odd numbers (1 and 3) are added to x (1+3=4).
Tutorials, Roadmaps, Bootcamps & Visualization Projects