π Lesson 2.2: Loops β Making Things Repeat
Why write a block ten times when you can tell Scratch "do this ten times"? Loops are the first idea that makes kids feel like real programmers β and they're the secret behind every animation and game.
π― Learning Objectives
- Use the repeat and forever loops
- Understand what goes inside a loop vs. outside it
- Build a smooth walking animation with a loop
- Recognize and fix a runaway "forever" loop
Estimated Time: 35 minutes β’ Builds on: Sequences (2.1)
In This Lesson
π Learn It: Why loops exist
Imagine you want the cat to take 20 little steps. You could drag in 20 "move" blocks. Painful β and if you wanted 21, you'd start over. A loop says "do this again and again" so one block replaces twenty.
π© The hard way
β¦and 16 more. No thanks.
π The loop way
One loop. Change 20 to 100 in a heartbeat.
Loops live in the orange Control category. Notice they're C-shaped β blocks you place inside the "mouth" of the C get repeated.
π Learn It: repeat vs. forever
| Loop | What it does | Use it when⦠|
|---|---|---|
| repeat 10 | Runs the inside blocks a set number of times, then moves on | You know how many times (blink 3 times, take 20 steps) |
| forever | Runs the inside blocks endlessly until you press stop | Something should always be happening (a heartbeat, constant fall, always checking a key) |
β οΈ "forever" never ends on its own
Any block placed after a forever loop will never run β the program never gets past it. That's not a bug in Scratch; it's the loop doing its job. Use the red stop to end it.
π Learn It: What goes inside the loop
This is the idea kids (and adults!) trip on: only the blocks inside the C repeat. Compare:
Say is inside β repeats
"Ha!" three times.
Say is outside β runs once
Moves 3Γ, then says "Done!" once.
π οΈ Try It: A real walking cat
In Module 1 the cat "jumped" across. With a loop we get smooth walking. The cat has two costumes; alternating them while moving looks like real steps.
- Start with when π© clicked, then go to x: -200 y: 0 (start at the left).
- Add a repeat 20 loop (Control).
- Inside the loop, add: move 20 steps, next costume, and wait 0.1 seconds.
Press the green flag: the cat strides across the stage, legs moving. That's your first animation! The wait 0.1 sets the walk speed β smaller is faster.
π‘ Challenge: make it pace back and forth forever
Wrap the whole walk in a forever loop and add if on edge, bounce (Motion) plus set the sprite's rotation style to "left-right" so it flips instead of going upside-down. Now it patrols endlessly until you hit stop.
π¬ Teach It: Loops all around us
Loops are everywhere in daily life β naming them together makes the abstract idea stick.
Spot-the-loop game
"Brushing teeth is a loop: scrub, scrub, scrub β repeat until clean! Can you think of another loop? What about the wheels on the car, or a song's chorus?"
- Stirring a pot β’ jumping jacks β’ a ticking clock β’ steps while walking β’ a chorus repeating.
The powerful question
When your child copy-pastes the same block many times, don't correct β ask:
"That works! Is there a block that could do all of those for us at once, so we don't have to make so many?"
Letting them discover the loop is far stickier than telling them.
π§ Ages 5β7
Stick to repeat with small numbers they can count out loud. "Repeat 3 β let's count the jumps!"
π§ Ages 8β11
Great age for the walking project. Let them tune the wait number and feel how it changes speed.
π§ Ages 12+
Introduce a loop inside a loop (nesting). E.g., repeat 4 { repeat 10 { move; wait } turn 90 } to trace a square.
β οΈ Common kid bug
They drop a block below the loop expecting it to repeat, or they trap the whole program in a forever so a later block "does nothing." Point at the C-shape: "Is your block inside the mouth, or outside?"
π― Quick Check
Question 1: You want the cat to blink exactly 5 times. Best loop?
Question 2: Only which blocks repeat in a loop?
Question 3: A block placed after a "forever" loop willβ¦
Summary & What's Next
π Key Takeaways
- repeat runs a set number of times; forever runs until you press stop.
- Loops are C-shaped β only the blocks inside repeat.
- Alternating costumes inside a loop creates smooth animation.
- Let kids discover loops by asking "could one block do all these?"
π Next up
So far the cat does what we plan. In Lesson 2.3 it starts making decisions β reacting to key presses and touches with if/then and sensing blocks. This is where projects become interactive.