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.

Lesson 1 of 5PROAges 10+
See what PRO unlocks →

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 - 1

Output

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 - 1

Here'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...")
  • It repeats forever — patience > 0 never becomes False
  • It runs exactly 3 times, then stops on its own
  • It causes an error immediately, before running at all

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.

Unlock this lesson with PRO →

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 →