Python while Loops, break and continue for Kids

A while loop repeats for as long as something stays true, which makes it the right tool when you do not know in advance how many times to go round.

  • 15 exercises
  • 5 lessons
  • Ages 10+
  • PRO

This topic is part of PRO — a one-time $49.99 purchase, no subscription. Topics 1–3 are free, start to finish, and the first level needs no account.

For parents & teachers

What this topic covers

A for loop runs a known number of times. A while loop runs until a condition stops holding — which is more flexible and considerably easier to get wrong. The classic failure is forgetting to change the thing being tested, so the condition never becomes False and the loop runs forever.

Rather than warning about infinite loops in the abstract, this topic puts children in front of them safely. All code runs in a sandbox with an execution limit, so a runaway loop stops on its own and becomes something to diagnose rather than something to fear.

break and continue follow, and the distinction between them is drawn sharply: break abandons the whole loop, continue abandons only the current pass. Children who blur the two write code that looks nearly right and behaves nothing like it should.

Built around a real misconception

The mistake this topic is built to fix

Common mistake

A child uses continue expecting the loop to stop, or break expecting it to skip one item.

Why the topic is built around it

The two are easy to blur because both interrupt the normal flow. The topic contrasts them on the same task so the difference in result is obvious rather than described.

whileloops.pyPython 3
gold = 0while gold < 3:    gold = gold + 1    print(gold)
Output1 2 3

Explain · Ask · Guided · Practice

The lessons, in order

Each lesson explains one idea in short steps, checks it landed with a question, walks through a guided first try, then leaves the child to practise on their own.

  1. A loop that runs until a condition stops being True — and the trap of forgetting to update it.

    • Explain
    • Ask
    • Guided 1 level
    • Practice 2 levels
  2. Stopping a loop the instant something happens, before its condition would end it naturally.

    • Explain
    • Ask
    • Guided 1 level
    • Practice 2 levels
  3. break stops everything. continue skips just this one pass and keeps going.

    • Explain
    • Ask
    • Guided 1 level
    • Practice 2 levels
  4. while, break, and continue — all three, working together.

    • Explain
    • Ask
    • Guided 1 level
    • Challenge 2 levels
  5. Off-by-one at the edge of a while loop — and the update that has to happen on EVERY branch, not just one.

    • Explain
    • Ask
    • Guided 1 level
    • Practice 2 levels

Lessons unlock in order within a topic, so nothing arrives before the idea it depends on. This topic is part of PRO — $49.99 unlocks it along with everything else.

Try it now

The very first level needs no account at all — see whether it clicks before signing up for anything.

Play the first level free