Session 4 — Events & Loops
Duration: 60 min · Format: live online
Session goal: by the end, students can use event blocks to start code in three ways and loop blocks to repeat it — and explain the "game loop" that keeps a program running.
Soft skill focus — Critical thinking
Today's human skill: Critical thinking. Events and loops make you stop and reason: what starts this code, and what makes it repeat — the exact thinking behind the "game loop."
- Build it in class: before you press the green flag on each demo, ask students to predict how many times a
repeat 10or aforeverwill run and why. When they changeforevertorepeat 3in the activity, have them explain the difference they see rather than just watching it. - Reflection (wrap-up): ask "How can you tell whether some code should run once, a set number of times, or forever?"
Before class — prep
- Open Scratch in a tab (signed in if you can, so you can save) and be ready to screen-share the editor.
- Have the events and loops diagram below open to share.
- Have a sprite on the stage in the middle, ready to move.
- If any student can't run Scratch, have the low-tech fallback (clap-loop game) ready — see Teaching notes.
Hook
Play "start and repeat." Say: "When I say GO, clap your hands over and over until I say STOP." Do it. Then ask: "What was the GO? What was the repeat?"
Reveal the two big ideas: "GO was an event — it starts the action. Clapping over and over was a loop — it repeats the action. Every game you've ever played is built from exactly these two things: something starts the code, and a loop keeps it running. Today you build both."
Teach — Events: three ways to START code
Share this diagram and explain what an event and a loop each do:
Explain: Event blocks are the yellow "hat" blocks at the top of a script. They answer the question "when should this code start?" A script does nothing until its event happens. Build these live on your shared screen — three different starts for the same sprite.
Build this together:
1. when green flag clicked → say "The flag started me!" for 2 seconds. Press the green flag to run it.
2. when [space] key pressed → move 50 steps. Now press the space bar — the sprite jumps. Show the little dropdown: you can pick any key (up arrow, a, etc.).
3. when this sprite clicked → play sound Meow. Now click the sprite on the stage — it meows.
when green flag clicked
say "The flag started me!" for 2 seconds
when space key pressed
move 50 steps
when this sprite clicked
play sound Meow
Explain the big idea: one sprite can have many scripts, each with its own event hat. They wait quietly until their event happens — flag, key, or click. This is how a game reacts to a player.
⚠ Watch for the "nothing happens" trap: a stack with no hat block (or the wrong one) will never run. If pressing space does nothing, check the script actually starts with
when space key pressed— not just a loosemoveblock sitting by itself.
Ask: "You want the sprite to jump when the player presses a key. Which event block?" (Answer: when [space] key pressed.)
Teach — Loops: forever, repeat & wait
Explain: a loop repeats the blocks inside it, so you don't have to stack the same block a hundred times. Loops are orange Control blocks. Build these live.
repeat 10 — a set number of times. It wraps around the blocks inside and runs them exactly that many times:
when green flag clicked
repeat 10
move 20 steps
wait 0.2 seconds
Press the flag — the sprite takes 10 steps across the stage, then stops. Change 10 to 4 and watch it do fewer.
forever — never stops. This loop repeats forever, until you press the red stop button:
when green flag clicked
forever
next costume
move 5 steps
if on edge, bounce
Press the flag — the sprite walks and animates non-stop. Explain: forever has no notch at the bottom — nothing can snap below it, because nothing after it would ever run.
wait 1 seconds — a pause. Show that without a wait, loops run so fast you can barely see each step. Adding wait 0.2 seconds inside a loop slows it to human speed. Wait is how you control the pace.
Now name the big idea — the game loop. Put an event on top of a forever loop:
when green flag clicked
forever
move 5 steps
if on edge, bounce
Say it out loud: "The event STARTS the code. The loop REPEATS it." That pattern — start once, then repeat forever — is called the game loop, and it runs under every video game in the world.
Ask: "Which loop would you use to make a sprite walk non-stop?" (Answer: forever.)
Activity — Event + loop = keep it moving
Students combine an event and a loop. Demo the first step, then let them go and circulate.
- Open a new project at Scratch.
- Game loop: build
when green flag clicked → forever → move 5 steps → if on edge, bounce. Press the flag — the sprite paces non-stop. - Add a key event: on a second script, build
when [space] key pressed → repeat 10 → change color effect by 25 → wait 0.1 seconds. Press space and watch it flash. - Add a click event: on a third script, build
when this sprite clicked → say "Ouch!" for 1 seconds. - Make it yours: change the
repeatnumber, thewaittime, and which key starts the flash. Try swapping aforeverfor arepeat 10and notice the difference.
Circulate and ask: "Show me the block that starts this script. Show me the block that repeats. What happens if you change forever to repeat 3?"
Debrief: ask 2–3 students to share their screen and run all their event scripts for the class.
Check for understanding
Ask these aloud or in the chat. Answer key (for you):
- What does an event block do, and what colour is it? → It starts a script when something happens (flag, key, click). Events are yellow hat blocks.
- What's the difference between
repeat 10andforever? →repeat 10runs the inside blocks exactly 10 times, then stops;foreverruns them over and over until you press stop. - In one sentence, what is the "game loop"? → An event starts the code and a loop repeats it — start once, then keep going.
Wrap-up + homework
- Ask one student to explain, in one sentence, the difference between "start" and "repeat."
- Homework — Start and repeat: make a sprite that starts with the green flag and walks forever with
if on edge, bounce, plus one thing that happens when you press a key. Screenshot it for your portfolio.
Teaching notes
- Correct this misconception: "a loop runs its blocks side by side, all at once." No — a loop runs the inside blocks top to bottom, then jumps back up and does them again. It's fast repetition of an order, not everything happening together. Trace one lap slowly with your finger so they see the path.
- Fast finishers (extension): have them nest ideas — a
foreverloop with arepeat 4inside it, or two different key events (up arrowanddown arrow) that move the sprite different ways. Ask them to predict whatrepeat 0does before they try it (answer: nothing — zero times). - Low-tech fallback: no devices? Play "human loops." Give a student a card: "repeat 3: hop, spin." They must do hop-spin, hop-spin, hop-spin — exactly three times, then stop. Give another: "forever: wave" — they wave until you shout STOP (the red button). The class feels the difference between a counted loop and a forever loop.
Vocabulary
| Term | Meaning |
|---|---|
| Event | Something that STARTS a script (flag, key press, click) |
| Hat block | The yellow event block that sits on top of a script |
| Loop | A block that REPEATS the blocks inside it |
| forever / repeat | Repeat with no end / repeat a set number of times |
| Game loop | An event starts the code, a loop keeps it running |
Resources
- Scratch editor — where students build (free, in the browser).
- Scratch Ideas page — official tutorials, including "Make It Fly" and "Pong Game".
- Scratch Starter Guide (PDF) — a one-page getting-started sheet.
Practice set
Extra tasks to explore events and loops. Work them easy → hard, at lab time or for homework. Answers follow each arrow.
1. Colour clue. Event hat blocks are which colour, and loop blocks are which colour? → Events are yellow; loops (Control) are orange.
2. Start it. Which block starts a script when you click the sprite? → when this sprite clicked.
3. Count or forever. Which loop stops on its own after a set number: repeat 10 or forever? → repeat 10 — it runs 10 times, then stops.
4. Predict. The script is when [space] key pressed → repeat 3 → move 20 steps. What happens when you tap space once? → The sprite moves 20 steps three times (60 steps total), then stops.
5. Make it (build task). Build a script so the sprite walks non-stop and bounces off edges when the green flag is clicked. → when green flag clicked → forever → move 5 steps → if on edge, bounce.
6. Fix it (harder). A student built move 50 steps → wait 1 seconds but says "it just runs once and never repeats." What one block would make it repeat forever, and where does it go? → Wrap the two blocks in a forever loop (drag forever around them); also add a hat like when green flag clicked on top so it can start.
Going deeper (optional)
Optional — for a class that's got the game loop running and wants to know why it matters.
Every game is a loop. Behind the scenes, a video game does the same tiny job dozens of times a second: check the controls, move things a little, draw the screen, repeat. That's a forever loop. When students build forever → move → if on edge, bounce, they're building the exact skeleton of a real game engine — just simpler. Point out that this one pattern will carry them all the way to the catch game and maze game in Unit 3.
Events make things happen "at the same time." Because each script has its own hat, a sprite can seem to do many things at once — walk forever and flash when you press space and talk when clicked. They aren't really simultaneous deep down, but Scratch runs them so fast it looks that way. This is how a game listens to a player while the action keeps going.
Common mistakes & fixes
- Mistake: A stack of blocks with no hat, so nothing ever runs. → Fix: add an event on top (
when green flag clicked,when [space] key pressed, orwhen this sprite clicked). - Mistake: Trying to snap a block under
foreverand finding it won't attach. → Fix:foreverhas no bottom notch on purpose — put those blocks inside the loop, or userepeat 10if you need code to run after. - Mistake: A loop runs so fast you can't see anything happen. → Fix: add a
wait(e.g.wait 0.2 seconds) inside the loop to slow it down. - Mistake: Pressing a key does nothing because the wrong key was chosen in the dropdown. → Fix: open the dropdown in
when [ ] key pressedand pick the key you're actually pressing. - Mistake: Using
foreverwhen the action should happen a set number of times. → Fix: swap inrepeat 10(or whatever count) so it stops on its own.
Next session
Session 5 — If–Then Decisions: the start of Unit 2 — Code That Thinks. Students learn to make their code decide — using if … then with Sensing blocks like touching — so a sprite can react differently depending on what's happening.