One-sentence summary
A loop is a structure that lets a Scratch sprite do a job many times without placing the same blocks over and over.
Why it matters
Imagine you want a sprite to draw a square. A square has four sides, so you would need to stack the "move" and "turn" blocks four times. Now what if you wanted to draw a star, or a shape with thirty sides? Dragging the same blocks thirty times is tiring and very easy to get wrong.
This is exactly where loops help. By saying "repeat these blocks a certain number of times," we describe a long job with one small structure. The code becomes shorter, and when we want to change something, fixing a single number is enough.
In the algorithms module we learned the idea of repetition: gathering the same steps inside a loop. Scratch makes that idea visible with the repeat blocks in the orange Control category. The conditions we learned in the previous lesson show up here too, because some loops rely on a condition to decide when to stop.
The three repeat blocks in Scratch
In Scratch, loops live in the orange Control category. There are three basic repeat blocks. Let us meet each one, then see it with an example.
1. "forever"
This block repeats the blocks inside it without ever stopping on its own. It has a beginning but no natural end; the sprite keeps going until the green flag is stopped. It is used for continuous motion, constant sensing or an animation.
Example: A sprite moving across the stage and bouncing off the edge without ever stopping.
when green flag clicked
forever
move 10 steps
if <touching edge?> then
turn 180 degrees
Here we combined "move 10 steps" from the Motion category with the "touching edge?" block from the Sensing category. The sprite moves continuously, turns back when it touches the edge, and this goes on forever.
2. "repeat"
If we know from the start how many times we want to repeat, we use this block. The number inside it sets how many times it runs. After that many turns, the loop stops on its own.
Example: A sprite drawing a square by moving and turning four times.
when green flag clicked
pen down
repeat 4
move 100 steps
turn right 90 degrees
pen up
Here the "pen down" block from the Pen category makes the sprite leave a trail behind it. The sprite moves and turns 90 degrees four times, so a square appears on the stage.
3. "repeat until"
Sometimes we do not know in advance how many times to repeat, but we can describe when the loop should stop using a condition. This block runs until the condition inside it becomes true. The moment the condition is true, the loop stops.
Example: Have the sprite move toward the mouse pointer until it touches it.
when green flag clicked
repeat until <touching mouse-pointer?>
point towards mouse-pointer
move 5 steps
Here the "touching mouse-pointer?" block from the Sensing category is the condition. The sprite moves toward the mouse until it reaches it, then stops immediately. We do not need to know in advance how many steps it will take.
Drawing polygons with the pen
One of the best examples of loops is drawing polygons. The Pen category lets the sprite leave a trail as it moves. With a loop, we move the sprite along each side and turn it at every corner.
Finding the rule: the turn angle
Finding how many degrees to turn at each corner is easy: divide 360 by the number of sides. The sprite's turning must add up to one full circle of 360 degrees.
- Triangle: 3 sides → 360 ÷ 3 = 120 degrees
- Square: 4 sides → 360 ÷ 4 = 90 degrees
- Pentagon: 5 sides → 360 ÷ 5 = 72 degrees
- Hexagon: 6 sides → 360 ÷ 6 = 60 degrees
Example: A sprite drawing a hexagon
when green flag clicked
set pen color to blue
pen down
repeat 6
move 80 steps
turn right 60 degrees
pen up
In this program the sprite moves six times and turns 60 degrees at each corner. The result is a regular hexagon. If you change the number of repeats and the turn angle using the rule above, you can draw any polygon you like. Changing a loop is as easy as changing a single number.
Hands-on practice
Write a program that makes a sprite draw an octagon (an 8-sided shape) with the pen.
- What number should go in the "repeat" block?
- How many degrees should the sprite turn at each corner? (Hint: divide 360 by the number of sides.)
- Sketch the block sequence on paper first, then try it in Scratch. Do not forget to place "pen down" before the loop.
When you finish, change the repeat number and the angle so the same program draws a triangle. Which two numbers draw a triangle?
Common mistakes
Forgetting the "pen down" block
The sprite runs the loop and moves across the stage, but no trail appears. This usually happens because the "pen down" block from the Pen category was not placed before the loop. If you want a trail, you must put the pen down before the drawing starts.
The wrong turn angle
If the "repeat" number is right but the shape does not close, the turn angle is usually wrong. When a shape will not close, recalculate using the "divide 360 by the number of sides" rule. For example, if you write 60 instead of 90 for a square, the shape will not close.
No wait inside "forever"
If you put only a color or costume change inside a "forever" loop, the change happens so fast that your eyes cannot follow it. Animations usually need a block such as "wait 1 seconds" from the Control category.
One repeat too few or too many
A very common mistake is a loop that runs one time too few or too many. If you write 3 instead of 4 when drawing a square, one side will be missing. To be sure, test with a small number and count the sides with your eyes.
Safety note
This lesson is done entirely on screen, with no electronics or tools. Still, because the "forever" block keeps a program running without stopping, it is easy to stay in front of the screen for a long time. Take a break every 20–30 minutes, look away from the screen and rest your eyes. When you explore other people's projects on Scratch or write comments, do not share personal information (address, phone number, school name) and make sure an adult knows.
Lesson summary
- A loop lets us do a job many times without placing the same blocks over and over.
- The "forever" block repeats the blocks inside it without stopping; it is used for continuous motion and sensing.
- The "repeat" block is used when we know the number of repeats from the start.
- The "repeat until" block runs until a condition becomes true and depends on a stopping condition.
- When drawing a polygon with the pen, the turn angle is found by dividing 360 by the number of sides.
Review questions
- What is the main difference between the "forever" block and the "repeat" block?
- To make a sprite draw a pentagon with the pen, how many times should the loop repeat and how many degrees should it turn at each corner?
- You want the sprite's pen to leave a trail as it moves, but no line appears. What is the most likely reason?
- In what situation is the "repeat until" block a better choice than the "repeat" block?
- What shape does the following block sequence draw on the stage?
pen down
repeat 3
move 100 steps
turn right 120 degrees
pen up
Answers
- The blocks inside "forever" repeat until the program is stopped, without ending on their own. The "repeat" block stops by itself after running the number of times we wrote.
- It should repeat 5 times and turn 72 degrees (360 ÷ 5) at each corner.
- The most likely reason is forgetting to place the "pen down" block from the Pen category before the loop. If the pen is not down, the sprite moves but leaves no trail.
- When we do not know in advance how many times to repeat, but we can describe when the loop should stop with a condition. For example, tasks like "move until touching an edge."
- It draws a triangle. The sprite moves three times and turns 120 degrees (360 ÷ 3) at each corner.
Source and verification note
For “Loops in Scratch”, verification focuses on whether the relationship between The three repeat blocks in Scratch and 2. "repeat" remains consistent across examples. Block names are kept consistent with the current core Scratch categories. Project behaviour should be tested separately for start-up, normal play, errors and restarting.
Next lesson
Variables and Lists