CurriculumPython while Loops, break and continue for Kidsbreak — leaving early
Python break Statement: Leaving a Loop Early
Stopping a loop the instant something happens, before its condition would end it naturally.
break — leaving early
Sometimes you want to stop a loop RIGHT NOW, before its condition would naturally end it. That's break.
break exits the loop immediately — right where it is, mid-pass, no matter what the condition says.
room = 0
while room < 5:
print(room)
if room == 3:
break
room = room + 1Output
0
1
2
3room never reaches 5 here — the loop stopped itself the moment room hit 3, three steps before the condition would have.
room = 0
while room < 5:
print(room)
if room == 3:
break
room = room + 1Not every while loop needs a break, though. Plenty just run their natural course and stop on their own condition.
Check your understanding
room = 0, while room < 5. The loop prints 0, 1, 2, 3 and then stops. Did room ever reach 5?
room = 0
while room < 5:
print(room)
if room == 3:
break
room = room + 1Why: break stops the loop the instant it runs, regardless of the loop's own condition. room was still 3 — well short of 5 — when the loop ended. That's the whole point of break: an early, deliberate exit.
What you'll practice
The dragon searches 5 rooms, numbered 0 to 4, printing each room number — but STOPS the instant it reaches room 3, where the treasure is. Print rooms 0, 1, 2, 3, then stop — never reach 4.
More from this topic
break — leaving early is one lesson inside Python while Loops, break and continue for Kids — see the full lesson order and what the whole topic covers.
View the full topic →