🎨 Phase 2 · Animation Skills 🟢 Beginner MODULE 06

Loops — Work Smarter

⏱️ 30 min
📖 Theory + Build
🧩 5 Quiz Questions
🏗️ 1 Challenge
Your progress in Phase 250%
🎯 What you'll learn: The two most powerful loop blocks in Scratch — Repeat and Forever — and why loops are the smartest coding trick ever. Then build a Dancing Robot that grooves non-stop!

Why Do We Need Loops?

Imagine you want a sprite to spin 10 times. Without loops, you'd have to drag 10 "turn" blocks. With a loop, you just write it once and tell Scratch how many times to repeat it!

❌ Without loops (messy!)
turn 36 degrees
turn 36 degrees
turn 36 degrees
turn 36 degrees
turn 36 degrees
turn 36 degrees
turn 36 degrees
turn 36 degrees
turn 36 degrees
turn 36 degrees
✅ With loops (clean!)
repeat (10)
  turn 36 degrees
end
Same result, 10x less code!

Repeat vs Forever — Choose the Right Loop

🔢
Repeat
Control block — yellow-orange
repeat (10)
Runs the blocks inside a specific number of times, then stops and continues to the next block.
🎯 Use when: you want something to happen a set number of times — spin 5 times, flash 3 times, jump 10 times.
♾️
Forever
Control block — yellow-orange
forever
Runs the blocks inside non-stop until you press the red stop button. Nothing comes after forever (it never ends!).
🎯 Use when: you want continuous action — animations, walking, checking for keyboard presses, game loops.
HOW A FOREVER LOOP WORKS — FLOW DIAGRAM
🚩 When flag clicked
♾️ Forever
Do something
Keep going?
YES (always!)
NO (stop button)
STOP ⏹
1. Flag clicked — loop starts
2. Runs the blocks inside
3. Jumps back to the start
4. Repeats endlessly!
FeatureRepeat (N)Forever
Runs a set number of times✅ Yes❌ No
Runs forever until stopped❌ No✅ Yes
Code can continue after it✅ Yes❌ No
Best for animations👍 Sometimes✅ Usually
Best for game loops❌ No✅ Yes

Build: Dancing Robot 🤖

Let's build a robot that dances forever using both types of loops — a Forever loop for continuous dancing, and Repeat inside for each dance move!

1
Set up your robot
Open Scratch and add a "Robot" sprite from the library. Add a stage backdrop — "Stars" or "Space" looks great! Put the robot in the centre of the stage.
2
Add the dance loop
Drag a when 🚩 clicked block. Then add a forever block underneath. Inside forever, we'll put all the dance moves.
3
Add Move 1: The Spin
Inside the forever, add repeat (4). Inside that, add turn 90 degrees and wait 0.2 seconds. This makes the robot spin once slowly.
4
Add Move 2: The Slide
After the spin repeat, add another repeat (3). Inside: change x by 30, wait 0.1 secs. Then another repeat to slide back!
5
Add colour effects
Inside the forever loop, add change color effect by 10 at the end. Now the robot will cycle through rainbow colours as it dances!
Dancing Robot — Complete Code
SCRATCH BLOCKS
when 🚩 clicked
set color effect to (0)
forever

  -- Move 1: Spin --
  repeat (4)
    turn ↻ (90) degrees
    wait (0.2) seconds

  -- Move 2: Slide right --
  repeat (3)
    change x by (25)
    wait (0.1) seconds

  -- Move 3: Slide left --
  repeat (3)
    change x by (-25)
    wait (0.1) seconds

  -- Rainbow colour --
  change color effect by (15)
  next costume
Why add wait blocks?
Without wait blocks, Scratch runs so fast the animation is invisible — it all happens in a fraction of a second! Wait blocks slow things down so we can actually see the movement. Try 0.1 seconds for fast moves, 0.3 for slower ones.

Bonus: Nested Loops 🪆

You can put a loop inside another loop! This is called a nested loop. The inner loop runs completely every time the outer loop runs once.

Nested Loops Example
SCRATCH BLOCKS
repeat (3)          ← outer loop runs 3 times
  repeat (4)        ← inner loop runs 4 times each
    turn (90) degrees
    wait (0.1) seconds
  move (50) steps

Result: spins 4 times, moves, spins 4 times, moves, spins 4 times, moves
Total turns = 3 × 4 = 12 turns!
🧩 Knowledge Check — Lesson 6
5 loop questions. Test your knowledge!
1. What is the main purpose of a loop in Scratch?
2. What is the difference between "Repeat 10" and "Forever"?
3. Can you add code blocks AFTER a "Forever" loop?
4. Why do we use "wait" blocks inside animation loops?
5. A "Repeat 3" loop contains a "Repeat 4" loop inside. How many total times does the inner loop run?
💪
Scratch Challenge — Lesson 6
Loop mastery · Beginner Level
Challenge: Fireworks Display 🎆

Create a fireworks display using loops!

Requirements:
1. A firework sprite that glides to a random position then grows (using Repeat + change size by)
2. Use Forever to keep launching new fireworks
3. After each burst, reset the size with set size to 10%
4. Change colour with each burst so fireworks are different colours
5. Add a pop or bang sound effect when each firework bursts
💡 Show hints if you're stuck
  • Forever → go to random position → repeat 10 (change size by 5) → play sound → set size to 10
  • Add change color effect by (25) after each burst for rainbow fireworks
  • Try the "Stars" backdrop to make it look like a night sky
  • Add multiple copies of the firework sprite for simultaneous explosions!
Finished this lesson?
Mark it complete to track your progress.
🤖

Lesson 6 Complete!

Loop master! Next up: Draw with Pen — make Scratch draw beautiful art automatically!

Module 06 of 16Phase 2 — Animation Skills