CurriculumPython while Loops, break and continue for Kidswhile — repeat until something changes
Python while Loops Explained: Repeat Until Something Changes
A loop that runs until a condition stops being True — and the trap of forgetting to update it.
while — repeat until something changes
for loops repeat a NUMBER of times, decided in advance. while loops are different — they repeat UNTIL something changes.
while CONDITION: keeps going as long as the condition is True. No fixed count anywhere.
patience = 3
while patience > 0:
print("Pacing...")
patience = patience - 1Output
Pacing...
Pacing...
Pacing...Every pass checks the condition FRESH. The moment patience hits 0, the loop stops — nobody tells it '3 times', it just keeps going until False.
patience = 3
while patience > 0:
print("Pacing...")
patience = patience - 1Here's the trap: if nothing inside the loop ever changes patience, the condition is ALWAYS True. The loop never stops.
patience = 3
while patience > 0:
print("Pacing...")If that happens for real, you'll see a message about your code getting stuck in a loop, and it reboots automatically. That's not a crash — it's the game catching exactly this.
Check your understanding
patience = 3, and the loop body never changes patience. What happens?
patience = 3
while patience > 0:
print("Pacing...")Why: Nothing inside the loop ever changes patience, so patience > 0 stays True forever, and the loop never ends. This is the single most common while-loop mistake — always ask yourself: what, inside this loop, actually changes the condition?
What you'll practice
The dragon paces back and forth while its patience is above 0. Patience starts at 3 and drops by 1 each pace. Print 'Pacing...' each time it paces.
More from this topic
while — repeat until something changes 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 →