Skip to the content
Peabody TeachFor teachers and grown-ups

🪜 The Stair Robot: Loops with a Count v0.1.0

Students program a "robot" on a taped grid with repeat cards and if-else cards, predicting the path before it runs. It teaches that a loop takes a count and that if-else picks a path.

  • For: 3rd to 5th
  • Time: about 40 minutes
  • The question: How do you say "do it this many times" and "do this or that" to a robot?
  • CSTA (2017): 1B-AP-10

You will need

  • Masking tape for a 6 by 6 grid on the floor, or the printable mat
  • The printable's cards
  • A small object for the goal
  • Pencil and the prediction sheet

The lesson, step by step

  1. Set the grid

    Mark a six-by-six grid with tape (or lay out the printable mat). Put a start square, a goal square and two or three "wall" squares the robot must not step on. Show the cards: forward, turn left, turn right, repeat __ times, and if wall ahead / else.

  2. A program with a count

    As a class, program the robot from the start across a long row with "repeat 5 times: forward". Ask: "How would we say this without a loop?" Count five forward cards and show the saving.

  3. Predict first

    Hand out the prediction sheet. Each pair lays out a short card program, then draws on the mat where they think the robot will end up before anyone walks it. Predicting before running is the habit that matters most.

  4. Run the robot

    One student is the robot and follows the cards exactly. The partner records the real path on the mat. Compare it with the prediction. When they differ, do not say who is right: trace the cards one at a time together.

  5. Add if and else

    Add the card "if wall ahead, turn right, else forward" inside a repeat: "repeat 8 times: (if wall ahead turn right, else forward)". Predict, then run. This is the first program the robot can use on a grid it has not seen.

  6. Same program, new grid

    Move the walls and run the same card program again. Ask why it works on a map the programmer never saw. Say that this is the reason programs have if and else.

Questions to ask while they work

  • Before it runs, where will it end up?
  • What does the repeat do each time round?
  • What does the robot check before each step?
  • What would change if we repeated 6 times?

If it goes fast

  • Write the shortest program that reaches the goal.
  • Count how many cards a program has with a loop, and how many without.
  • Add a repeat inside a repeat to walk around the edge of the grid.

The printable

Cut the cards apart. The sheet has a six-by-six mat to draw predictions and real paths on, one mat for each program.

◂ Find the Bug in the Recipe · All ten lessons · The Scoreboard Game ▸

Nothing on this page is sent to us. The printable has a blank name line and no child's details. No sign-in, no ads.