1
Say it once, repeat it
Computing 2: Unit 4, pp. 54–65
GoalUse a repeat block to do the same thing again and again, and say how many times it runs.
New words
repeat · to do something againrepeat block · a block that runs the blocks inside it again and againcount · how many times
Explanation
Sometimes a character must do the same thing again and again. We could use the same block many times. There is a shorter way. We put the block inside a repeat block. The number on the repeat block says how many times the blocks inside it run. In the picture, four quarter turns make one whole spin both ways. Repeat blocks make programs shorter and easier to read.
Worked examples
A rabbit moves right 2 four times. The long way uses four blocks. The short way uses one repeat block with 4. The rabbit moves 2 × 4 = 8 squares either way.
Repeat 3 with a say block inside makes the character say Hi! three times.
In words, the algorithm is: start on tap, repeat 4 times: grow by 1, stop. The character grows four times, so it gets bigger and bigger.
Class activity
Repeat dance: write a dance of three moves on paper, for example clap, stamp, spin. Now think of a move that you do many times, such as clap. Instead of writing clap five times, write “repeat 5: clap” and do it. Count out loud: one, two, three, four, five. Then change the number on the repeat to 3 and do it again. How does the number change what happens?
Practice
1
How many times does the character hop?
4 times.
2
Write a shorter program for this one, using a repeat block.
Start on the green flag, repeat 5 times: hop 2, stop.
3
How many squares does the character move in all?
3 × 2 = 6 squares.
4
Why is a repeat block useful?
It makes the program shorter and easier to read, so we do not write the same block again and again.