Lesson 4: Repeat Blocks in Scratch
Estimated time: 15-20 minutes | Scratch Activity
What You Will Learn
By the end of this lesson, your child will be able to:
- Find and use the Repeat block in Scratch
- Find and use the Forever block in Scratch
- Draw shapes using loops with the Pen extension
- Create a simple loop animation
Meet the Repeat Block
In the last three lessons, you learned about loops using words, clapping, and drawing. Now it is time to see loops in action on a computer! In Scratch, the loop block is called repeat (10).
Repeat Block: A Scratch block that runs the blocks inside it a specific number of times. You choose the number. Whatever blocks you put inside the repeat block will happen that many times.
The Repeat block is shaped like a mouth -- it wraps around other blocks. The blocks inside the mouth are the loop body (the steps that repeat). The number tells Scratch how many times to run them.
Scratch Activity: Find the Repeat Block
Step 1: Open Scratch at scratch.mit.edu and start a new project.
Step 2: Click on the Control category (the orange blocks).
Step 3: Find the repeat (10) block. It has a number you can change and a mouth shape where other blocks fit inside.
Step 4: Drag a move (10) steps block from the Motion category and snap it inside the repeat block.
Step 5: Click the stack to run it. The cat moves! But it went so fast you might not have noticed it repeated 10 times.
Drawing a Square with a Loop
One of the coolest things you can do with loops in Scratch is draw shapes. Remember in Lesson 2, we saw that drawing a square is really a loop? Let us build it!
Scratch Activity: Draw a Square
First, add the Pen extension (click the blue button at the bottom left of Scratch, then choose "Pen").
Build this stack of blocks:
erase all
pen down
repeat (4)
move (100) steps
turn right (90) degrees
pen up
What happens: The cat draws a perfect square! The loop body is "move 100 steps, turn right 90 degrees" and it repeats 4 times -- once for each side of the square.
Talk About It (Parent and Child)
Ask your child: "What would happen if you changed the 4 to a 3? What shape would that make?" (A triangle!) "What about 6?" (A hexagon!) Let them try it. Changing the number in the Repeat block changes how many sides the shape has.
Shape Challenge
Try making these shapes by changing the repeat number and the turn angle:
- Triangle: Repeat 3, turn 120 degrees
- Square: Repeat 4, turn 90 degrees
- Pentagon: Repeat 5, turn 72 degrees
- Hexagon: Repeat 6, turn 60 degrees
- Circle (sort of!): Repeat 36, turn 10 degrees, move 10 steps
The secret: the turn angle times the repeat number should equal 360. That makes the shape close back where it started.
Meet the Forever Block
The Repeat block stops after a set number of times. But what if you want something to keep going and never stop? That is what the forever block does.
Forever Block: A Scratch block that runs the blocks inside it over and over without stopping. It only stops when you click the red stop button. This is an "infinite loop" -- a loop with no end.
The Forever block is great for things that should keep happening the whole time your project is running, like a character that keeps walking, a background that keeps scrolling, or a game that keeps checking if you pressed a key.
Scratch Activity: Bouncing Cat
Build this stack of blocks:
forever
move (10) steps
if on edge, bounce
What happens: The cat walks across the screen, bounces off the edge, walks back, bounces off the other edge, and keeps going forever! Click the red stop button to make it stop.
Loop Animations
Loops are the secret behind all animations. An animation is just a loop that changes something a tiny bit each time -- like moving a little, changing the color a little, or switching between costumes.
Scratch Activity: Walking Animation
Build this stack of blocks:
forever
move (5) steps
next costume
wait (0.2) seconds
if on edge, bounce
What happens: The cat walks across the screen and its legs move! The "next costume" block switches between the two cat costumes, and the loop makes it happen over and over. That is animation -- a loop of small changes.
Scratch Activity: Color-Changing Shape
Add the Pen extension if you have not already, then build this:
erase all
pen down
repeat (36)
move (50) steps
turn right (100) degrees
change pen color by (10)
What happens: The cat draws a beautiful star-like pattern that changes color as it goes! Each time through the loop, the pen color shifts a little, creating a rainbow effect.
Repeat vs. Forever: When to Use Which
Now you know two loop blocks. But when should you use each one?
Use Repeat When...
- You know exactly how many times something should happen
- You are drawing a shape with a set number of sides
- You want something to happen a specific number of times and then stop
- Examples: draw a square (4 times), spin around once (repeat 36, turn 10 degrees), say something 3 times
Use Forever When...
- You want something to keep happening the whole time your project runs
- You are making an animation or a game
- You want to keep checking for something (like a key press or a mouse click)
- Examples: keep the cat walking, keep checking if two sprites are touching, keep the background moving
Talk About It (Parent and Child)
For each of these, ask your child whether they would use Repeat or Forever: (1) Make the cat spin in a circle exactly once. (2) Make the cat keep bouncing around the screen. (3) Draw a triangle. (4) Keep checking if the player pressed the space bar. Answers: 1=Repeat, 2=Forever, 3=Repeat, 4=Forever.
Activity: Your Own Loop Project
Scratch Activity: Build Your Own (10 minutes)
Choose one of these challenges:
- Shape artist: Use a Repeat block and the Pen to draw a shape you have not tried yet. Change the number of repeats, the step size, or the turn angle and see what happens.
- Dance party: Use a Forever block to make the cat keep switching costumes and moving. Add a second sprite and make it dance too!
- Spiral: Use a Repeat block with the Pen, but change the step size each time through the loop. Start with "move 5 steps" and add 2 steps each time. This makes a spiral!
Experiment tip: Change the numbers and see what happens! What if the repeat is 100 instead of 10? What if the turn angle is 91 instead of 90? Tinkering is how you learn.
Check Your Understanding
1. What does the Repeat block do in Scratch?
2. What is the difference between Repeat and Forever?
3. To draw a triangle with a loop, what number would you put in the Repeat block?
Key Takeaways
- The Repeat block in Scratch runs blocks inside it a set number of times
- The Forever block keeps running blocks inside it until you press stop
- You can draw shapes with loops: move, turn, repeat for each side
- Animations are loops that make small changes each time (move a little, change costume, shift color)
- Use Repeat when you know how many times; use Forever when it should keep going
- Changing the numbers inside loops changes the result -- always experiment!
You Finished All the Lessons!
Practice Activities
Try the practice challenges to keep building your loop skills with fun activities and Scratch projects.
Practice ActivitiesModule Quiz
Ready to test what you know? Take the Module 5 quiz and see how much you have learned about loops!
Take the Quiz