AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

The repeat block

Week 9 · Unit 4: Be a storyteller · 3 lessons
1

The repeat block

Computing 4: Unit 4, pp. 48–61
GoalUse the repeat block in Scratch to run blocks a set number of times.
New words
repeat block · a Scratch block that runs the blocks inside it a set number of timesnumber box · the white oval where you type a numberrun · to carry out the blocks of a script
Explanation

The repeat block is in the Control group. It has a number box and a mouth. Type a number in the box and the blocks inside the mouth run that many times. When the last trip is done, the script carries on with the blocks underneath. This is the big difference from the forever block, which never lets the script carry on. The repeat block is how we make a count-controlled loop in Scratch. If the loop holds the block “move (10) steps” and the number is 7, the sprite moves 70 steps in all. Change the number and you change how many times the loop runs.

whenclickedmove10stepswait1secondsrepeat4sayDone!for2seconds
Worked examples
whenclickedgo to x:0y:0move10stepsrepeat5
A sprite starts at x: 0. The loop moves it 10 steps five times, so it ends at x: 50. Then the script is finished.
x 240−240y 180−180start x −100end x 20
A snail starts at x: −100. It moves 20 steps and waits half a second, six times. The six moves add up to 120 steps, so it ends at x: 20. The loop takes 6 × 0.5 = 3 seconds.
foreverwhenclickedmove5stepswait0.5secondsforeverrepeatwhenclickedmove5stepswait0.5secondsrepeat6
Compare the two loops. They hold the same blocks, but the repeat loop stops after six trips and the forever loop never stops.
Class activity

Be the repeat block (with a friend): write a number on a card, such as 6. You are the repeat block and hold the card. Your friend is the sprite and hops once each time you say “go”. Count the hops out loud and stop when the count matches the card. Now say “Done!” once. Change the card to 3 and guess how many hops there will be before you start. Try a loop with two actions: hop and clap.

Practice
1
How many times does the sprite say “Hi!” and how many seconds does the loop take?
whenclickedsayHi!for1secondsrepeat3
2
A sprite starts at x: 20. What is its x position at the end?
whenclickedgo to x:20y:0move15stepsrepeat4
3
Why is repeat (8) better than writing “move (10) steps” eight times?
4
Which script stops by itself? How far does it turn in all?
Awhenclickedturn ↻15degreeswait0.2secondsforeverBwhenclickedturn ↻15degreeswait0.2secondsrepeat5