Unit 2 · Coding for Kids · Grades 1–3
Loops: Repeat the Steps
What if the same step happens again and again?
In Unit 1 you lined steps up in order. That is a sequence. Sometimes a sequence says the same thing many times: clap, clap, clap, clap.
Writing that by hand gets long. There is a shorter way.
The big idea: A loop is a way to say “do these steps again.” In this unit we will use a Repeat block to pack those repeated steps into a shorter program.
1. What is a loop?
A loop tells a computer, or a robot, or our turtle, to do some steps more than once.
You already use loops in real life. If a recipe says “stir 10 times,” you do the same stir, again and again, until you have done it 10 times. You do not need 10 different instructions.
In a program, a loop does that same job: it repeats a step, or a short list of steps, a certain number of times.
2. Spot the repeats
Look at this list:
- Clap
- Clap
- Clap
- Clap
Every line says the same thing. That is a repeated sequence. When you see the same step in a row, you have found a good place for a loop.
Grown-up note
The K–12 Computer Science Framework says young learners should be able to spot repeated sequences, and that simple loops can repeat instructions.
3. The Repeat block
We will pack those repeated steps into a Repeat block. It has two parts:
- a number, which says how many times to run the steps inside, and
- the steps inside, which are the steps that get repeated.
So this long list:
- Step forward
- Step forward
- Step forward
- Step forward
does the same job as:
Repeat 4 times: Step forward
4. Why loops help
A Repeat block is shorter to read. It is also easier to change. If you need five steps forward instead of four, you change the number from 4 to 5. You do not have to add a whole new line.
A computer still follows the steps exactly. A Repeat block does not guess. If you write “Repeat 4 times: Step forward,” the turtle will step forward four times, no more and no less.
5. More than one step inside
The steps inside a Repeat block can be more than one line. That short list is called the body of the loop.
A long time ago, the Logo coding language used a repeat command like this. To draw a square, you can write the long way:
forward 50, right 90, forward 50, right 90, forward 50, right 90, forward 50, right 90
Or you can write the short way, with a repeat:
repeat 4 [forward 50 right 90]
Those two programs do the same job. The repeat version says: do “go forward, then turn right” four times. That traces the four sides of a square. (The 50 is a Logo distance. Our turtle just steps one square at a time.)
On our grid, a square with sides that are two steps long looks like this:
Repeat 4 times: Step forward, Step forward, Turn right
6. A loop inside a loop (a stretch)
Here is a challenge, if you want it. You can put a Repeat block inside another Repeat block. Some people call that a nested loop.
Try this one:
Repeat 2 times: (Repeat 2 times: Step forward)
The inside block steps forward 2 times. The outside block runs that inside block 2 times. So the turtle steps forward 2 + 2, which is 4 steps in all.
You do not need nested loops for most of this unit. They are here as a stretch. This unit does not use variables or “if” questions. We are only practicing repeat.
Try the turtle lab and the self-guided quiz at jugami.com/kid-coding/loops/
7. Turtle lab
The turtle starts in the bottom left square, facing up. It still understands Step forward, Turn left and Turn right. A turn happens in place. Now you can also add a Repeat block. Use + and − to change how many times it runs. Click “Add steps here” to put steps inside a Repeat block.
Puzzle A: Pack the steps
These steps take the turtle to the star, but they say the same thing again and again. Build a Repeat block that does the same job. Then run it.
The long way:
- Step forward
- Step forward
- Step forward
Your shorter program:
New steps go on the main list.
Puzzle B: Turn, then repeat
Now the star is three squares to the right of the start. The turtle still starts facing up, so it will need a turn. Use a Repeat block for the steps that happen more than once.
New steps go on the main list.
Puzzle C: A stretch challenge
The star is at row 3, column 3. Try a Repeat block with more than one step inside. For an extra challenge, put a Repeat block inside another Repeat block.
New steps go on the main list.
8. Be the robot: an unplugged game
You don’t need a computer to practice loops. Play this game with a friend or a grown-up.
- Pick a spot in the room, like a chair. That is the goal.
- One person is the coder. The other is the robot.
- The coder plans the steps first. You may use “Step forward,” “Turn left,” “Turn right,” and “Repeat ___ times:” with steps inside.
- The robot does each step exactly, and nothing else. When the coder says a Repeat block, the robot does the steps inside, then does them again, until the number is done.
- Did the robot reach the goal? If not, debug the steps and try again. Then switch jobs!
For a stretch, try a Repeat inside a Repeat, like “Repeat 2 times: (Repeat 3 times: Step forward), then Turn right.”
Grown-up note
Agree on what one “step” means before you start (for example, one heel-to-toe step). Clear the path of anything that could trip someone. When a Repeat is used, help the robot count out loud so the number of repeats stays exact. Follow the words literally, even if a shorter path is obvious.
Practice problems
Worksheet: Loops: Repeat the Steps
Open the worksheet and use your browser’s Print command to print it, or try the problems below. They use new examples, not the ones in the self-guided quiz, and they have no answer key.
- Write a Repeat block that does the same job as: Stomp, Stomp, Stomp, Stomp, Stomp, Stomp.
- Are these the same number of claps? Repeat 2 times: Clap, Clap. And: Repeat 4 times: Clap.
- Stretch: Repeat 2 times: [Repeat 4 times: Tap]. How many taps is that?
Self-guided quiz
Eight questions. Pick an answer to see a hint.
Score: 0 of 8 · 0 answered
Sources
We checked the facts on this page with these sources.
- K–12 Computer Science Framework: statements by concept — young learners should be able to identify and describe repeated sequences; simple loops can be used to repeat instructions; computers follow instructions literally.
- Code.org, Unplugged Activities for K–5, Lesson 6: Getting Loopy — an unplugged lesson for grades 1–2 that uses a dance and a repeat loop to show how loops make instructions shorter.
- CS Unplugged (University of Canterbury): Kidbots — an unplugged activity where children give a “robot” instructions, test them, and track down bugs.
- Logo Foundation (MIT Media Lab): A Logo Primer — Logo has a repeat command;
repeat 4 [forward 50 right 90]draws a square, and the long form of those same steps does the same job. - Logo Foundation (MIT Media Lab): Logo History — the first Logo was made in 1967 by a team Seymour Papert worked with; the first turtle was a robot on the floor.
- MIT News: Professor Emeritus Seymour Papert dies at 88 (2016) — Seymour Papert’s life (born 1928 in Pretoria, South Africa; died 2016) and his work on children, computers and learning.
Lesson text, drawings, the turtle lab and share cards are original Jugami work made for this course. No historical quotations are used. Our teacher Seymour is a friendly character inspired by Seymour Papert (1928–2016); he is not a real person speaking.