Learn it
Sometimes we need to do the same thing many times. Instead of copying the same blocks again and again, we use a loop. A loop repeats the blocks inside it.
In Scratch, repeat (10) runs the blocks inside it 10 times. Loops make code shorter and easier to change.
π§° Tool: free Scratch online editor (no account needed to try; a parent can create one to save projects) or the free ScratchJr app for tablets.
Code examples
Without a loop
when green flag clicked
move (10) steps
move (10) steps
move (10) steps
move (10) steps
With a loop
when green flag clicked
repeat (4)
move (10) steps
end
Same result with fewer blocks. To go further, just change 4 to 20.
Project: Clap loop
- Stand up. Clap 3 times, then jump. Do that 4 times. That’s a loop!
- In Scratch, make the cat say ‘Hop!’ and move 20 steps, 5 times, using one repeat block.
- Change the number to 10. What happens?
Challenge: Write down another loop from real life (like climbing stairs).