Chapter 03

Patterns, Sequences & Loops

Primary
At a glance
Core ideaA loop repeats a chunk of steps instead of writing them out again and again.
Key termLoop — "repeat this N times" captured in a single instruction.
You can…Spot repetition and collapse it into one tidy loop.
Watch outChange the repeated steps in one place, not in a hundred copies.
Theory

A pattern is something that repeats in a predictable way — red, blue, red, blue, red, blue. A sequence is a list of things in a particular order. When part of a sequence repeats over and over, we call that repeating part a loop.

Instead of writing "clap, clap, stomp" four separate times, we can say: repeat "clap, clap, stomp" 4 times. That single instruction is a loop — it says how many times to do something, so we don't have to write it out again and again.

Explanation

Loops save enormous effort. Imagine writing a separate instruction for a robot to take each of 100 steps forward — one hundred lines that all say the same thing! A loop lets us say it once: "take a step, and do that 100 times." Real computer programs use loops constantly, from games that check every second whether you pressed a key, to a washing machine that repeats its spin cycle.

Big idea. Whenever you find yourself repeating the exact same instruction again and again, that's a sign a loop could do the job in one line instead.

Practical

Activity: Pattern Beads. Using two colours of beads (or two crayons), make a pattern that repeats: red, red, blue — red, red, blue — red, red, blue. Say out loud: "repeat red-red-blue, three times." Then invent your own repeating pattern and challenge a partner to guess the loop instruction that makes it.

Bonus: Clap Loop. Stand in a circle. One person calls out a loop like "repeat clap-clap-stomp, 4 times" and everyone performs it together, counting the repeats out loud.

Q&A
Q1 What is a loop?

A loop is an instruction to repeat a set of steps a certain number of times (or until something happens), instead of writing those steps out over and over.

Q2 Why do programmers use loops instead of writing the same instruction many times?

It saves a lot of writing, and it's easier to fix — if you need to change what happens each time, you only fix it in one place instead of a hundred copies.

Q3 Can you think of a loop from real life?

A washing machine repeats "fill, wash, drain, spin" until it's done. A merry-go-round repeats the same circle again and again. Both are loops — a set of steps happening over and over.

Concept mind map

How the ideas connect

Every key idea in this chapter, branching from the core concept — use it to see the whole picture at a glance.

repeat N timesloop bodypatternless writingcounterstop conditionPatterns, loops
Infographic

The process, step by step

Step 1Set countDecide how many times to repeat, for example 5.
Step 2Run bodyDo the repeated chunk of steps once.
Step 3CheckHave you repeated enough times yet?
Step 4Repeat or stopIf not done, run the body again; when the count is reached, stop.
Solved examples

Worked problems, step by step

Follow each solution line by line, then try to reproduce it on paper before moving on.

Example 1Rewrite this using a loop: step, step, step, step (four times).

  1. Notice the same step repeats four times.
  2. Collapse it into one instruction.

Example 2A loop says "repeat 3 times: clap". How many claps happen?

  1. The body is one clap.
  2. It runs 3 times.
Practice problem set

Now you try

Work each one out first, then tap to reveal the worked answer.

1What is a loop?
A loop repeats a chunk of steps instead of writing them out again and again.
2Why are loops useful?
They save writing, make patterns clear, and let one instruction stand for many repeats.
3What is the loop body?
The chunk of steps that gets repeated each time the loop runs.
4Rewrite "jump, jump, jump, jump, jump" as a loop.
Repeat 5 times: jump.
5What tells a loop when to stop?
A stop condition or a counter, such as repeating a set number of times.
6What is a pattern in steps?
A group of steps that repeats, which you can spot and fold into a single loop.