Skip to content
Jugami
Coding for Kids · Seymour

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:

  1. Clap
  2. Clap
  3. Clap
  4. 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:

So this long list:

  1. Step forward
  2. Step forward
  3. Step forward
  4. Step forward

does the same job as:

Repeat 4 times: Step forward

Two panels. The left panel is titled The long way and lists four steps: 1. Step forward. 2. Step forward. 3. Step forward. 4. Step forward. The right panel is titled With a Repeat block. A green box says Repeat 4 times, and inside it is one step: Step forward. Under the box it says Same job, fewer lines.
Four Step forward steps, packed into one Repeat block that runs 4 times.

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.

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.

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.

  1. Pick a spot in the room, like a chair. That is the goal.
  2. One person is the coder. The other is the robot.
  3. The coder plans the steps first. You may use “Step forward,” “Turn left,” “Turn right,” and “Repeat ___ times:” with steps inside.
  4. 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.
  5. 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.

  1. Write a Repeat block that does the same job as: Stomp, Stomp, Stomp, Stomp, Stomp, Stomp.
  2. Are these the same number of claps? Repeat 2 times: Clap, Clap. And: Repeat 4 times: Clap.
  3. 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.

1. What is a loop in a program?
2. Jamal hops three times: Hop, Hop, Hop. Which Repeat block does the same job?
3. Why do people use Repeat blocks?
4. A turtle faces up. It gets “Repeat 2 times: Turn right.” What happens?
5. Which program uses a Repeat block with more than one kind of step inside?
6. A program says: Repeat 3 times: [Repeat 2 times: Clap]. How many claps is that?
7. Priya writes: Wave, Wave, Wave, Wave, Wave. She wants a shorter program. What should she write?
8. A robot is told “Repeat 3 times: Spin.” What will it do?

Score: 0 of 8 · 0 answered

Sources

We checked the facts on this page with these sources.

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.