CurriculumPython while Loops, break and continue for KidsThe Full Night Patrol

Practice Challenge: while, break, and continue Together

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

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

The Full Night Patrol

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

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

room = 1
while True:
    if room == 5:
        break
    print(room)
    room = room + 1

Output

1
2
3
4

Check break conditions BEFORE continue conditions when both could apply — otherwise you might skip past the one that should have stopped everything.

Check your understanding

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 early
  • 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.

What you'll practice

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.

Unlock this lesson with PRO →

More from this topic

The Full Night Patrol 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 →