Learning Goals 3 min
By the end of this lesson you will be able to:
- Use
foreverto keep a set of blocks running with no end. - Explain why nothing can ever be snapped underneath a forever loop.
- Choose between
repeat (10)andforeverfor a given job.
Warm-Up 7 min
Your loop repeats a beat neatly. But it always stops after however many times you typed — and a dance party that ends after eight beats is a short party.
Quick-fire puzzle
Aisyah wants her cat to keep bopping all through the party. She tried this. What goes wrong?
when flag clicked
repeat (1000)
turn cw (15) degrees
wait (0.1) seconds
end
Reveal the answer
It works — for about a hundred seconds. Then it stops dead, in the middle of the party. A big number is not the same as no number.
And she cannot simply guess higher. Any number she picks will run out eventually, which means the party has a hidden expiry date she never chose.
New Concept — a loop that never ends 15 min
Think of forever as a heartbeat. It runs whatever is in its mouth, then runs it again, and again, and never stops of its own accord. Something outside has to end it.
Blocks reference
| Block | Category | What it does |
|---|---|---|
forever | Control | Runs the blocks in its mouth over and over with no end. Only the stop sign halts it. |
if on edge, bounce | Motion | From Lesson 13. Inside a forever it stops becoming a one-off and becomes a rule. |
Two differences you can see
Forever looks almost exactly like the repeat block, with two important changes.
- No number. There is nothing to count, so there is no input to type in.
- No notch underneath. The bottom of the block is smooth, so nothing can snap below it.
That second one is not a design accident. Anything placed after a forever could never run, so Scratch removes the possibility of the mistake entirely. The shape of the block is telling you the truth about how it behaves.
when flag clicked
forever
move (5) steps
if on edge, bounce
end
Which loop for which job?
| Loop | How long it runs | Best for |
|---|---|---|
repeat (10) | Exactly that many times, then moves on. | Shapes, counted routines, anything with a definite end. |
forever | Until somebody stops it. | Background motion, ongoing behaviour, anything that should not stop by itself. |
How a forever ends
For now, the red stop sign from Lesson 4. Click it and every script halts at once, wherever it happens to be. Next lesson you will learn to end a forever from inside the script itself, which is much tidier.
Why it matters
Forever is the heartbeat of nearly every Scratch game. The fish swims until the game ends; the enemy patrols until it is caught; the music keeps playing. It turns a one-off action into an ongoing rule.
Worked Example — the cat that never stops 15 min
We turn the one-off bounce from Lesson 13 into a rule that holds for as long as the project is running.
Step 1 — Recall the one-off version
Build the Lesson 13 stack: reset, face right, move, bounce. Click the flag and it happens once. Click it again and it happens once more. That is the ceiling of what you could do before today.
Step 2 — Fetch forever
From Control, drag forever into an empty part of the Script Area and look at it closely. No number. No notch on the bottom.
Step 3 — Put the motion inside
Drag the move and the bounce into the forever’s mouth, then snap the whole thing under the hat.
when flag clicked
forever
move (5) steps
if on edge, bounce
end
Step 4 — Click the flag and leave it alone
The cat crosses the stage, turns at the edge, comes back, turns again. It will keep doing this all lesson if you let it. Nothing you built before could do that.
Step 5 — Stop it
Click the red stop sign. The cat freezes exactly where it was. This is the only way to end it so far, and it is a slightly blunt instrument — next lesson gives you a better one.
Step 6 — Try to break the rules
Attempt to snap a say block underneath the forever. Scratch simply will not let you. Drag it around the bottom edge and nothing highlights, because there is no notch to grip.
Now put that same say block inside the mouth and run it. It fires every single pass, endlessly — usually far too fast to read, which tells you something about how many times a second this loop is going round.
Step 7 — Control the speed
Add wait (0.05) seconds inside the mouth. The motion becomes smooth and controllable rather than frantic. Inside a forever, a small wait is usually essential.
What changed: your project has gone from doing things to behaving. A rule now holds for as long as the project runs, rather than a list of actions finishing and stopping.
The full assembled stack (your reference)
when flag clicked
forever
move (5) steps
if on edge, bounce
wait (0.05) seconds
end
Try It Yourself — three small builds 12 min
Goal: Slow the endless bounce down until you can comfortably follow the cat with your eyes.
when flag clicked
forever
move (3) steps
if on edge, bounce
wait (0.05) seconds
end
Think: there are two ways to slow it — smaller steps or longer waits. Try each on its own and see which gives smoother motion.
Goal: Make the cat spin on the spot forever, instead of travelling. A disco spin rather than a patrol.
when flag clicked
forever
turn cw (10) degrees
wait (0.05) seconds
end
Think: take the wait out and the cat becomes an orange blur. The wait is not decoration here — it is what makes the spin readable.
Mini-mission: two things at once. Make the cat patrol the stage endlessly while a second sprite does something entirely different, also endlessly, from the same single flag click.
It works if: one flag click starts both, the two behaviours are visibly different, and neither ever stops until you press the stop sign. Keep each stack under 8 blocks.
Think: two forever loops both running endlessly sounds impossible — how can one finish so the other can start? Try it and see, then work out why it does not matter.
Mini-Challenge — before and during 5 min
“The entrance and the patrol”
Build a script where the cat makes a one-off entrance first, and only then settles into an endless routine. Once the endless part starts, it must never stop on its own.
It works if:
- One flag click starts everything.
- The entrance happens exactly once — not on every pass of the loop.
- The routine afterwards never stops by itself.
- Running it a second time gives an identical entrance.
Reveal one valid solution (teacher)
when flag clicked
go to x: (-180) y: (0)
say [Let's dance!] for (1) seconds
forever
turn cw (15) degrees
move (4) steps
if on edge, bounce
wait (0.05) seconds
end
The entrance blocks sit above the forever, so they run once. Pupils who put them inside get the cat announcing itself several times a second — memorable, and instantly diagnosable.
Recap 2 min
Forever is a loop with no number and no notch underneath — because there is no “after” a loop that never ends. It turns actions into ongoing behaviour, which is what makes projects feel alive. It needs a wait inside to stay watchable, and for now the only way to stop it is the red stop sign.
- forever (block)
- A Control c-block that repeats its contents endlessly. Nothing can be attached below it.
- Endless loop
- A loop with no built-in ending. Something outside it has to stop it.
- Stop sign
- The red octagon above the Stage. Halts every running script at once.
- Behaviour
- A rule that holds while a project runs, rather than a one-off action.
Homework 1 min
The endless patrol. Build a cat that patrols the stage forever, then experiment with what makes it look good.
- Build the four-block endless bounce from the Worked Example.
- Try step sizes of 2, 5 and 15. Note which looks best.
- Try it with no wait inside, then with
0.05, then with0.5. - Screenshot your favourite version and write down the numbers you chose.
when flag clicked
forever
move (5) steps
if on edge, bounce
wait (0.05) seconds
end
Bring back next class:
- Your screenshot and your chosen numbers.
- Your answer to: “Why can you not snap a say block underneath the forever loop — and where would you have to put it instead?”
Heads up for next class: SCR-L01-21 teaches the stop block, so a forever loop can finally end without you reaching for the red octagon.