Python gives you three statements for controlling exactly how a loop behaves from the inside: break to stop the loop entirely, continue to skip straight to the next iteration, and pass to do absolutely nothing — a placeholder for code you haven't written yet. They're small keywords, but mixing them up is a common source of subtle bugs.
break — Stop the Loop Immediately
break exits the loop completely, right away, skipping any remaining iterations — even if the loop's condition would otherwise still be true.
numbers = [4, 9, 15, 22, 7, 3]
for num in numbers:
if num % 2 == 0:
print(f"First even number found: {num}")
break # stop looking as soon as we find one
print(f"{num} is odd, keep looking...")
Output:
9 is odd, keep looking...
15 is odd, keep looking...
First even number found: 22
Notice the loop never even looks at 7 or 3 — once break runs, the loop is over.
continue — Skip to the Next Iteration
continue skips the rest of the current iteration's code and jumps straight back to the loop's condition check (or the next item, for a for loop) — the loop keeps running, it just skips one pass.
for num in range(1, 8):
if num % 2 == 0:
continue # skip even numbers entirely
print(num)
Output:
1
3
5
7
pass — Do Nothing (On Purpose)
Python doesn't allow an empty code block — an if, loop, function, or class body can't just be blank, it will raise an IndentationError. pass exists purely to satisfy that requirement when you genuinely want to do nothing, usually as a placeholder while you're still sketching out your code's structure.
for num in range(5):
if num == 2:
pass # TODO: handle this case later
else:
print(num)
def not_implemented_yet():
pass # function stub, to be filled in later
Output:
0
1
3
4
Unlike continue, pass doesn't skip anything — it's simply a no-op statement that lets the surrounding code (which otherwise would be empty) run without error. A good way to remember the difference: continue affects loop flow, pass affects nothing at all.
