Learn Python
>>> control_flow.break_continue_pass

break, continue & pass in Python

#concept

These three statements give finer control inside loops. break exits the loop immediately, skipping any remaining iterations entirely. continue skips just the rest of the current iteration and jumps straight to the next one. pass does absolutely nothing — it's a placeholder used where Python's syntax requires a statement but you don't have one yet.

#how it works
1

break exits the loop immediately

Skipping everything after it in that iteration and all future iterations.

2

continue skips only the current iteration

Execution then moves on to the next one as normal.

3

Both only affect the nearest enclosing loop

A break or continue inside a nested loop leaves the outer loop untouched.

4

pass does nothing at all

It exists purely to satisfy Python's syntax when a block can't be left empty.

5

pass is a common stand-in

While writing an if, function, or class you haven’t finished implementing yet.

#example
for i in range(6):
if i == 4:
break
if i % 2 == 0:
continue
print(i)
 
if False:
pass
print("Loop finished")
Output
1
3
Loop finished
1When i is 0, 0 % 2 == 0 is True, so continue skips straight to the next iteration — nothing prints.
2When i is 1, neither condition matches, so print(i) runs, showing 1.
3i is 2, then continue skips it again; i is 3, which prints.
4When i reaches 4, break fires immediately, ending the loop entirely — 4 and 5 are never even considered.
5The if False: pass block does nothing, since its condition is False anyway — pass is just there so the block isn’t left empty.
#use cases
Searching a list and stopping as soon as a match is found, using break to avoid checking the rest
Skipping invalid or unwanted items in a loop with continue, without an extra level of nested if
Stubbing out a function or class body with pass while planning the rest of the code
A placeholder exception handler with pass during early development

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in Python yourself — building beats watching.