← Course homeCode clears when you leave
MISSION 09 · PYTHON WHILE LOOPS

Stop Means Stop

Rover checks the tile ahead before every visit. Predict where it stops, count both successful moves and sensor checks, then inspect the real trace.

What’s saved: your code, predictions and answers clear when you leave this page or reload. If you turn saving on, only which puzzles you finished and how much help you used is kept on this device. Test accounts also share it, and lesson timing, with the site’s maintainer.

Next: M10 · Trust, but Test →

◇ Your mastery goalPython sensor while loops

Complete all 4 required tasks with a correct prediction, an inspected trace and an explanation that shows the concept. At least 3 must be independent checks, without answer-level help.

✓ Qualifying tasks: 0 / 4◎ Independent checks: 0 / 3 required
PRACTICE · 1 OF 4

Stop at the gate

0 / 4 checks

Rover is carrying a parcel east. Keep moving while the next tile is open; the wall marks the safe stopping point.

While rule: A qualifying program uses one while front_is_clear(): loop with an action-only indented body that includes a move. Before each body visit, the condition reads the tile directly ahead. A false first check skips the body; a safety run limit is an emergency guard, not the normal way this loop stops.

1
Predict before RunUse one-based column and row labels. Sensor checks are not moves: include the final false check.
2
Write the sensor loopIndent each robot action under the while line.

Allowed: while front_is_clear():, indented move(), turn_left(), turn_right(), comments and blank lines.

The condition is checked before the body each time. The loop can run zero times when the first check is false. A collision or run limit is not the intended stopping rule.

Allowed Python syntax

For a qualifying puzzle program, use exactly one top-level while front_is_clear(): with one or more indented robot actions. The bounded runner may accept other action-only experiments, but they do not earn this check. No counted for loop, conditions inside the body, assignments, counters, or nested loops.

FLOWCHART · INSPECTED PATH

Run an allowed program to reveal its flowchart. Predict first; then inspect every check and action.

Flowchart

✓ Inspected path ◆ Current step
Read or sketch this loop

A rounded shape starts or ends the program. A diamond asks Front is clear? at the robot’s current position and heading. TRUE enters the rectangle actions, in order; the back arrow returns to a fresh sensor check. FALSE leaves the loop. If the first check is FALSE, the body runs zero times.

Unlike for i in range(n), this loop has no fixed visit count. The body must change what the sensor sees so the loop can eventually stop. A safety limit stops experiments that keep repeating; that is a warning, not a normal FALSE exit.

On paper, draw Start → diamond. Label TRUE → body → back to diamond; label FALSE → End. Note the robot’s position and heading at each check. Keep the sketch beside you; no upload is needed. Tiny robot hats remain optional.

Run an allowed program to draw its sensor loop here.

MAP · FULL ROUTE

Predict Rover’s route

1, 3 · E

Start: column 1, row 3, facing E. Rover now: column 1, row 3, facing E. Goal: column 4, row 3. Walls at column 5, row 3.

Rover arrow★ goal■ wall

The wall or world edge provides the stopping condition.

4
Explain the stop conditionWhat controls how many times Rover moves? One explanation per completed, fully inspected run.
Choose an explanation
Help for this sensor puzzleHints build in steps. Worked help requires a deliberate choice.

Highest help used on this case in this session: none

Next: M10 · The Confidently Wrong Helper →

For Further Reading and Exploration

These are outside sites with their own rules. You will see a notice before you leave. Pick one, not all.

  • Automate the Boring Stuff with Python

    Free book to read online. The flow control chapter covers while loops, break and continue.

    • Hands-on
    • May need an install
    • Ask an adult
  • CS50's Introduction to Programming with Python

    Free Harvard course with videos and notes. The loops lecture covers while loops and how to make them stop.

    • Hands-on
    • Advanced
    • May count visits
  • MIT OpenCourseWare 6.100L

    Free college course notes and videos. It moves fast, so take one topic at a time. Look for the lecture on iteration, which covers while loops.

    • Hands-on
    • Advanced
    • May count visits
  • Blockly Games

    The Maze game has "repeat until" blocks, a block version of a while loop. Try one and see when it stops.

    • Hands-on