Loop Control Statements: break, continue & pass

Three statements for steering a loop mid-flight โ€” stop it entirely, skip one round, or do nothing at all.

Overview

Python provides three special statements to control the flow of loops (for and while):

All three examples in this note use the same base loop: for i in range(1, 11):, which iterates i from 1 to 10.

Key Concepts

Detailed Explanation

break

for i in range(1, 11):
    if i == 5:
        break
    print(i)

Output:

1
2
3
4

What happens: The loop prints i normally for 1, 2, 3, 4. When i becomes 5, the if condition is True, so break runs and the loop stops immediately โ€” it never reaches 6, 7, 8... even though range(1, 11) technically goes up to 10.

Note: break only exits the innermost loop it's placed in.

continue

for i in range(1, 11):
    if i == 5:
        continue
    print(i)

Output:

1
2
3
4
6
7
8
9
10

What happens: When i == 5, continue is triggered, so print(i) is skipped only for that one iteration (5 is never printed). The loop then moves on and continues normally for 6 through 10.

continue skips all remaining statements in that iteration

for i in range(1, 11):
    if i == 5:
        continue
    print(i)
    print("Hello")

Output (pattern):

1
Hello
2
Hello
3
Hello
4
Hello
6
Hello
7
Hello
8
Hello
...

What happens: For every value of i except 5, both print(i) and print("Hello") run. But when i == 5, continue skips both remaining print statements for that iteration โ€” not just the next line โ€” and jumps straight to i = 6. This demonstrates that continue skips everything below it in the loop body for the current pass, not just the immediately following statement.

pass

for i in range(1, 11):
    pass

What happens: This loop runs 10 times but does nothing on each iteration โ€” pass is just a placeholder. There is no output. It's typically used as a temporary stand-in while writing code, e.g., when you've defined a loop or function structure but haven't decided what should go inside yet.

Commands / Syntax Summary

StatementEffectScope of effect
breakExits the loop completelyEntire loop (remaining iterations don't run)
continueSkips to the next iterationOnly the current iteration
passDoes nothing (placeholder)No effect on control flow

Important Points

Things to Remember

Quick Revision

break stops the whole loop right now. continue skips the rest of this round and keeps looping. pass does nothing โ€” it's just a placeholder to keep the syntax valid. With range(1, 11) and if i == 5: break stops after printing 1-4, while continue prints 1-4, skips 5, then prints 6-10. Remember that continue skips all code below it in that loop cycle, not just the next line.