Practice Challenge: while, break, and continue Together

while, break, and continue — all three, working together.

  • Lesson 4 of 5
  • PRO
  • Ages 10+
  • 3 hands-on levels
See what PRO unlocksA one-time $49.99 purchase. Topics 1–3 are free.

The dragon explains

The Full Night Patrol

  1. The dragon: You have three tools now: while itself, break to stop, continue to skip. The challenge is choosing the right one, at the right moment.

  2. The dragon: A pattern worth knowing: while True: with a break inside is a completely valid way to write 'loop until something happens'.

    example.pyPython 3
    room = 1while True:    if room == 5:        break    print(room)    room = room + 1
    Output1 2 3 4
  3. The dragon: Check break conditions BEFORE continue conditions when both could apply — otherwise you might skip past the one that should have stopped everything.

Quick check

Check your understanding

Say your answer out loud before reading the marked one. Every wrong option is a mistake real beginners make.

  1. Question 1 of 1

    In a loop checking room == 10 (break) and room == 7 (continue), which should you check FIRST?

    • It depends on the specific numbers, but generally check break conditions earlyCorrect
    • It never matters what order if statements are checked in
    • continue should always come before break

    Why: There's no single rule that always applies — but when conditions COULD overlap, order decides which one actually fires. Think through your specific conditions rather than following a fixed pattern.

In the game

What you'll practice

Three levels in the game: one guided first try with the shape of the answer already there, then two to solve on your own.

  1. 1

    GuidedYour first try

    Patrol rooms 1 to 6. Skip room 4 (it's empty — don't print it, keep going). Stop the whole patrol the moment you reach room 6 — don't print it either.

  2. +2

    PracticeTwo more, on your own

This lesson is part of PRO.

PRO is a one-time $49.99 purchase, no subscription, and unlocks this whole topic along with everything else. Topics 1–3 are free, start to finish.

Unlock this lesson with PRO

Stuck three times? The game offers the answer — unasked.