Loops: Making Code Repeat (Year 4–5)

💻 Computer Science Years 4–5 Foundation

Learn how a loop repeats commands so you don't write them many times, use 'repeat 4 times' to draw a square, and count how many times a loop runs.

Open this lesson, with practice and a printable worksheet →

A loop is a block that repeats commands. Instead of writing the same block over and over, you put it inside a loop and tell the loop how many times to run.

Why this matters: Good coders are tidy and lazy in a clever way. If you need to do a thing 100 times, you would not want to drag 100 blocks. A loop lets you say it once and repeat it, which is faster and easier to fix.

The same code, two ways

Imagine you want a sprite to jump 3 times. Without a loop you write ‘jump’ three times. With a loop you write ‘jump’ once, inside a repeat 3 times block.

Without a loopWith a loop
jump
jump
jump
repeat 3 times {
  jump
}

Both make the sprite jump 3 times. The loop is shorter and easier to read.

Drawing a square with a loop

A square has 4 equal sides and 4 turns. To draw one, the sprite moves forward, then turns, and does this 4 times.

Put these steps in order to draw a square:

  1. Start the "repeat 4 times" loop
  2. Move forward 100 steps
  3. Turn right 90 degrees
  4. Loop back to the start, 4 times in all

Counting how many times a loop runs

The number in the loop tells you how many times the blocks inside run. So if there are 2 blocks inside a repeat 4 times loop, the sprite does 8 actions in total (2 blocks × 4 turns).

The square above needs just one small loop to draw.

Get the printable worksheet →
← Block Coding: Sequences & Events (Year 3–4) → Selection: Making Choices with 'if' (Year 5)
← Sasta Basta home All subjects