Skip to main content

πŸ” 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)

Ages 5–7 (with help) Ages 8–11 Ages 12+
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

move 10 steps
move 10 steps
move 10 steps
move 10 steps

…and 16 more. No thanks.

😎 The loop way

repeat 20
move 10 steps

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

The Control palette showing the 'repeat 10' and 'forever' C-shaped loop blocks near the top.
Figure 1: The two loops you'll use most β€” repeat and forever.
LoopWhat it doesUse it when…
repeat 10Runs the inside blocks a set number of times, then moves onYou know how many times (blink 3 times, take 20 steps)
foreverRuns the inside blocks endlessly until you press stopSomething 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

repeat 3
say Ha! for 1 seconds

"Ha!" three times.

Say is outside β†’ runs once

repeat 3
move 10 steps
say Done! for 1 seconds

Moves 3Γ—, then says "Done!" once.

flowchart TD A["Enter repeat 3"] --> B{"Done 3 times?"} B -->|No| C["Run inside blocks"] C --> B B -->|Yes| D["Continue below the loop"] style A fill:#FFAB19,color:#5c3d00,stroke:#333 style B fill:#5CB1D6,color:#fff,stroke:#333 style C fill:#4C97FF,color:#fff,stroke:#333 style D fill:#e2e8f0,color:#1e293b,stroke:#333

πŸ› οΈ 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.

  1. Start with when 🟩 clicked, then go to x: -200 y: 0 (start at the left).
  2. Add a repeat 20 loop (Control).
  3. Inside the loop, add: move 20 steps, next costume, and wait 0.1 seconds.
when βš‘ clicked
go to x: -200 y: 0
repeat 20
move 20 steps
next costume
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.