Lesson 3: Doing It Again — REPEAT Loops and Pattern Compression

Learning objective

Students will identify repeating patterns in an algorithm and rewrite them using REPEAT n TIMES loops, counting both single-command loops and multi-step block loops accurately.

Materials

Vocabulary

Lesson flow

1. Warm-up: The Clap-Tap-Snap Loop (7 min)

  1. Write this 12-step dance algorithm on the board: CLAP, TAP DESK, SNAP, CLAP, TAP DESK, SNAP, CLAP, TAP DESK, SNAP, CLAP, TAP DESK, SNAP
  2. Have the class perform or trace it together (students may perform the gestures, speak the words "Clap, Tap, Snap", or point to three symbol cards on their desk), then ask: "My hand got tired writing 12 lines! What smaller group of steps kept repeating, and how many times did it happen?"
  3. Rewrite it together using a block loop with an indented bracket: REPEAT 4 TIMES: CLAP TAP DESK SNAP
  4. Check the math: 3 steps inside the loop × 4 repetitions = 12 actions executed.

2. Direct instruction: Single-Step vs. Staircase Block Loops on a Grid (13 min)

Show two grid examples on the board starting at A1 facing North:

Example A — Crossing a straight hallway (A1 to A5): - Long version (4 lines): 1. FORWARD 1 2. FORWARD 1 3. FORWARD 1 4. FORWARD 1 - Looped version: REPEAT 4 TIMES: FORWARD 1

Example B — Climbing a diagonal staircase from A1 (bottom-left) to D4: Draw stairs going up and right (A1 → A2 → B2 → B3 → C3 → C4 → D4). 1. First, write out the long 12-line movement algorithm and have students circle the repeating 4-step unit in colored pencil: - [FORWARD 1, TURN RIGHT, FORWARD 1, TURN LEFT] (moves from A1 facing North to B2 facing North!) - [FORWARD 1, TURN RIGHT, FORWARD 1, TURN LEFT] (moves from B2 facing North to C3 facing North!) - [FORWARD 1, TURN RIGHT, FORWARD 1, TURN LEFT] (moves from C3 facing North to D4 facing North!) 2. Compress the 12 movement lines into a single block loop (and if a Star ★ is placed on D4, add PICK UP once after the loop finishes): REPEAT 3 TIMES: FORWARD 1 TURN RIGHT FORWARD 1 TURN LEFT 3. Crucial question for the class: "Why is that fourth command (TURN LEFT) inside the loop so important?" - Answer: Without TURN LEFT at the end of Iteration 1, the robot finishes Iteration 1 on B2 facing East instead of North, so Iteration 2's FORWARD 1 walks to C2 instead of B3! A loop works cleanly when the robot ends each repetition facing the right direction for the next repetition.

3. Guided practice: Loop Compression Workshop (15 min)

Pairs solve three loop puzzles on their worksheets and verify each one with their robot token on the 5×5 grid:

  1. Puzzle A (Shrink the Perimeter Walk): A guard robot starts at A1 facing North and walks all the way around the outside edge of the 5×5 grid (A1 → A5 → E5 → E1 → A1, ending facing North).
  2. Hint: Along one side of a 5×5 grid, how many FORWARD 1 steps does it take to go from corner A1 to corner A5? (Answer: 4 steps, because A1 → A2 → A3 → A4 → A5 is 4 moves!).
  3. Pairs write a loop that repeats 4 times to walk all 4 sides of the square.
  4. Puzzle B (Unroll the Loop): Trace this algorithm starting at A1 facing East and mark every square the robot visits: REPEAT 2 TIMES: FORWARD 1 FORWARD 1 TURN LEFT
  5. Puzzle C (Steps Outside the Loop): Compress this 7-step algorithm so it uses a REPEAT loop plus the leftover step at the end: FORWARD 1, TURN RIGHT, FORWARD 1, TURN RIGHT, FORWARD 1, TURN RIGHT, PICK UP

4. Wrap-up & Exit check (10 min)

  1. Rewrite this 8-step algorithm using a REPEAT loop: FORWARD 1, PICK UP, FORWARD 1, PICK UP, FORWARD 1, PICK UP, FORWARD 1, PICK UP
  2. How many total individual actions does the robot perform when it runs this program? TURN RIGHT REPEAT 3 TIMES: FORWARD 1 TURN LEFT PICK UP
  3. A robot starts at A1 facing North. It runs: REPEAT 3 TIMES: FORWARD 1 Does it land on A3 or A4? Explain why.

Worked answers for exit check

  1. Loop version: REPEAT 4 TIMES: FORWARD 1 PICK UP
  2. 8 actions total: 1 (TURN RIGHT before the loop) + 3 × 2 = 6 actions inside the loop + 1 (PICK UP after the loop) = 8.
  3. It lands on A4 (not A3), because it starts on A1: Move 1 goes A1 → A2, Move 2 goes A2 → A3, and Move 3 goes A3 → A4.