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
3

Loops in stories

Computing 4: Unit 4, pp. 48–61
GoalUse a repeat block inside an animated story and work out what happens and when.
New words
opening line · the first words of a story, said once before the loopone-off step · a step that happens once, so it stays outside the looptiming · how long each part takes
Explanation

Stories are full of things that happen again and again. A fisher casts a net, a frog hops along a path and a bird flaps its wings. In a Scratch story, the opening line and the ending line each happen once. The part that repeats goes inside a repeat block between them. When you read a story script, trace it part by part. Work out how long each part takes and which costume the sprite wears. The “say” block with a time waits until the time is over. The “next costume” block takes no time at all. Never put the ending under a forever block: the script would never reach it.

whenclickedsayTime to fish!for2secondssayCast the net!for1secondsnext costumewait1secondsrepeat3sayHome at last!for2seconds
Worked examples
TimeWhat happensCostume at the end
0–2 ssays “Time to fish!”1
2–4 sloop trip 12
4–6 sloop trip 23
6–8 sloop trip 31
8–10 ssays “Home at last!”1
The fisher has 3 costumes and starts on costume 1. This table traces the whole story. The story takes 2 + 3 × 2 + 2 = 10 seconds. After three “next costume” blocks the fisher is back on costume 1.
whenclickedsayReady?for1secondsmove20stepswait0.5secondsrepeat5sayI made it!for1seconds
A frog hops along a path. It says “Ready?” for 1 second, hops 5 times, 20 steps each, with half a second between hops, and then says “I made it!” for 1 second. It moves 100 steps and the story takes 1 + 5 × 0.5 + 1 = 4.5 seconds.
Loop blockWhat happens next
repeat (3)the story goes on to the last line
foreverthe story never reaches the last line
Compare what happens after the loop. With a repeat block the story reaches its last line. With a forever block it never does, and there is no room to attach a block underneath it.
Class activity

Act a story (with family): think of a short story with something that repeats, such as a fox that creeps forward 4 steps. Write the script on paper: one line for the start, one line for the loop with its number and one line for the end. Decide how many seconds each part lasts. Then act it out and count the seconds aloud. Does the real time match your plan? Change the number in the loop and act it again.

Practice
1
A baker sprite has 2 costumes and starts on costume 1. How many times does it say “Knead!”, which costume does it wear at the end, and how long does the script take?
whenclickedsayLet’s bake!for1secondssayKnead!for1secondsnext costumerepeat5sayBread is ready!for2seconds
2
How many seconds does this story take, and how far does the sprite move?
whenclickedsayReady!for1secondsmove10stepswait1secondsrepeat4sayGo!for2seconds
3
Write the blocks for a story in which a bird flaps 6 times and then says “Up!”.
4
Why should the ending line not be put under a forever block?