Lesson 2: Staircases and Borders — Shrinking Programs with REPEAT

Learning objective

Students will spot repeating groups of arrows inside a grid program, rewrite them using a REPEAT n TIMES: [ ... ] loop block, and verify that the long program and the loop program land on the exact same square.

Materials

Vocabulary

Lesson flow

1. Opening: The Staircase Climb (7 min)

  1. Draw a 4×4 Staircase Map where the explorer starts at S (Col 1, Row 1) and climbs diagonal stairs to T (Col 4, Row 4):
Row 4 (Top):    [ . ]  [ . ]  [ . ]  [ T ]
Row 3:          [ . ]  [ . ]  [ * ]  [ * ]
Row 2:          [ . ]  [ * ]  [ * ]  [ . ]
Row 1 (Bottom): [ S ]  [ * ]  [ . ]  [ . ]
                Col 1  Col 2  Col 3  Col 4
  1. Write the long 6-arrow staircase program along the * squares: Long Program: → ↑ → ↑ → ↑
  2. Ask: "Read or tap through that arrow list with me: 'Right, Up, Right, Up, Right, Up!' What 2-arrow pattern repeats over and over, and how many times does it repeat?"
  3. Pattern: [ → ↑ ], repeated 3 times!
  4. Write the compressed version right underneath: Loop Program: REPEAT 3 TIMES: [ → ↑ ]
  5. Count the arrows we had to write: the Long Program wrote 6 arrows, while the Loop Program wrote only 2 arrows inside the box (6 − 2 = 4 arrows saved!).

2. Main activity: Unrolling & Compressing Loops (18 min)

  1. Practice Unrolling a Loop (6 min):
  2. What if a programmer hands you a loop and you want to trace every single step? You unroll it!
  3. Write on the board: REPEAT 3 TIMES: [ ↑ ] followed by REPEAT 3 TIMES: [ → ]
  4. Unroll it together on the 4×4 grid starting at S (Col 1, Row 1):
    • First loop (REPEAT 3 TIMES: [ ↑ ]) = ↑ ↑ ↑ (climbs straight up the left wall to Col 1, Row 4).
    • Second loop (REPEAT 3 TIMES: [ → ]) = → → → (walks straight across the top row to T at Col 4, Row 4!).
  5. Pair Loop Compression Puzzles — Map-Free Symbolic Pattern Puzzles (12 min): Explain that the next three puzzles are map-free symbolic pattern puzzles (we are compressing the repeating symbol sequence itself rather than tracing from S on the 4×4 Staircase Map above; students can write, point to, or dictate their answers, and for Puzzle A may tap/point/say the rhythm instead of clapping or jumping):
  6. Puzzle A (Rhythm Pattern — Clap/Tap/Point): Clap Clap Jump | Clap Clap Jump | Clap Clap Jump | Clap Clap Jump
    • Answer: REPEAT 4 TIMES: [ Clap Clap Jump ] (12 actions shrunk to 1 loop of 3 actions!).
  7. Puzzle B (Symbolic Zig-Zag Arrow Sequence): ↑ ← ↑ ← ↑ ←
    • Answer: REPEAT 3 TIMES: [ ↑ ← ].
  8. Puzzle C (Symbolic Loop + Extra Step at the End!): → ↑ → ↑ → ↑ → (7 arrows total)
    • Guide students to see that the first 6 arrows are REPEAT 3 TIMES: [ → ↑ ], followed by one extra → outside the loop: REPEAT 3 TIMES: [ → ↑ ] then →.

3. Discussion questions (5 min)

4. Closing check (5 min)

  1. (Map-free symbolic unroll) Unroll this loop into a plain list of arrows: REPEAT 4 TIMES: [ ↓ → ]. How many total single-square steps does the unrolled list contain?
  2. (Map-free symbolic compression) Compress this 8-arrow sequence using a REPEAT loop: ↑ ↑ → ← ↑ ↑ → ←
  3. (4×4 grid trace) Start at (Col 1, Row 1) on an open 4×4 grid. Where do you land after running REPEAT 2 TIMES: [ ↑ → ]?

Worked answers for closing check

  1. Unrolled: ↓ → ↓ → ↓ → ↓ →. Since there are 2 arrows inside the box repeated 4 times, the token takes 4 × 2 = 8 total steps.
  2. REPEAT 2 TIMES: [ ↑ ↑ → ← ] (the 4-arrow pattern ↑ ↑ → ← repeats twice).
  3. Round 1 (↑ →) moves from (Col 1, Row 1) → (Col 1, Row 2) → (Col 2, Row 2). Round 2 (↑ →) moves to (Col 2, Row 3) → (Col 3, Row 3).

Differentiation