2
Repeat with more blocks
Computing 2: Unit 4, pp. 54–65
GoalTrace a repeat block that holds more than one block.
New words
inside · the blocks that sit within the repeat blockround · one run of all the blocks inside a repeat blocktrace · to follow a program step by step
Explanation
A repeat block can hold more than one block. All the blocks inside run once. That is one round. Then they run again until the number is used up. Repeat 3 with right 2 and spin right 12 inside runs: right 2, spin, right 2, spin, right 2, spin. Blocks outside the repeat run only once. Trace each round to find the result.
Worked examples
| After round | Across | Spins |
|---|---|---|
| start | 0 | 0 |
| 1 | 2 | 1 |
| 2 | 4 | 2 |
| 3 | 6 | 3 |
Blocks outside a repeat run only once. This character says Hi! one time, then goes up 1 and down 1 twice.
We can turn a long program into a short one. The long program does right 3 and up 1 three times. The short one puts right 3 and up 1 in a repeat block with 3.
Class activity
Human repeat: make three cards: take 2 steps forward, clap once, a repeat card with the number 3. Put the two action cards inside the repeat card. Run the program with your body and count your steps and claps. You should take 6 steps and clap 3 times. Then change the repeat number to 4. How many steps and claps now? Check your answers by doing it.
Practice
1
The character starts at 0 across and 0 up. Where does it finish?
6 across and 2 up. Each round moves 3 across and 1 up, and there are 2 rounds.
2
How many times does the say block run, and how many times does the hop block run?
The say block runs once. The hop block runs 3 times.
3
Write the short version: right 1, up 2, right 1, up 2, right 1, up 2, right 1, up 2.
Repeat 4: right 1, up 2.
4
A repeat block has the number 5 and a right 2 block inside. How far does the character move?
10 squares (5 × 2 = 10).