Python Control Flow
Python Break Continue and Pass
break, continue and pass give you fine control over how loops behave: stopping them early, skipping an iteration, or doing nothing as a placeholder.
The break Statement
break immediately exits the loop it is inside, skipping any remaining iterations entirely. Execution jumps straight to the first line of code after the loop.
for num in range(1, 10):
if num == 5:
break
print(num)1
2
3
4The continue Statement
continue skips the rest of the current iteration and jumps straight to the next one — the loop keeps running, it just moves on early for that particular pass.
for num in range(1, 6):
if num % 2 == 0:
continue
print(num)1
3
5The pass Statement
pass does nothing at all. It is a placeholder used when Python’s syntax requires a statement (like inside an if, loop, or function) but you have not written the real logic yet.
for num in range(5):
if num == 3:
pass # TODO: handle this case later
print(num)When to Use Each One
| Statement | Effect | Typical use case |
|---|---|---|
| break | Exits the loop completely | Stop searching once a match is found |
| continue | Skips to the next iteration | Skip invalid or unwanted items |
| pass | Does nothing, acts as a placeholder | Stub out code you will write later |
pass does not stop or skip anything — it is easy to confuse with continue at first, but pass simply lets execution flow through as if that line were not there.
Use pass while sketching out empty functions or classes, like def my_function(): pass, so your code stays syntactically valid while you plan the details.
