Back
🔄Loops & Repetition

Repeating steps efficiently

🔄

Loops: Repeating Steps Efficiently

Key Points

  • A LOOP repeats a set of instructions many times without having to write them out repeatedly
  • FOR loop: repeats a known number of times — 'FOR i = 1 TO 10: print i' prints numbers 1–10
  • WHILE loop: repeats AS LONG AS something is true — 'WHILE hungry: eat food'
  • Loops are one of the most powerful tools in coding — they handle huge tasks in just a few lines!

📘 Examples

How many times does this run? FOR i = 1 TO 5: print 'hello'

5 times! It prints 'hello' once for i=1, once for i=2, all the way to i=5!

A robot claps 10 times. How would you use a loop?

REPEAT 10 TIMES: clap. Just 2 lines of code instead of writing 'clap' 10 times!

What's the difference between a FOR loop and a WHILE loop?

A FOR loop repeats a specific number of times. A WHILE loop repeats as long as a condition is true — you might not know how many times it will run!

🌟 Fun Fact!

The first computer 'bug' was a REAL insect! In 1947, Grace Hopper's team found a moth stuck in a Harvard computer relay causing errors. They taped it in their logbook and wrote 'First actual case of bug being found'. 🐛

A loop repeats instructions rather than writing them out again and again. It is the point where children usually see why programming is powerful, because a loop does the same work in a fraction of the writing.

Loops connect directly to pattern recognition. Spotting that something repeats is what tells you a loop is possible, which is why patterns are taught first.

Ideas to build

  • That a loop repeats a set of instructions a number of times or until a condition changes.
  • That loops make programs shorter and easier to change, since you edit one place rather than many.
  • That a loop needs a way to stop, or it runs forever.
  • That loops can contain other loops, which is how grids and patterns are produced.

Things to do at home

  • Give an instruction like repeat four times: walk forward and turn right, and see the child trace a square.
  • Write out a repetitive task the long way and then rewrite it as a loop, comparing the length.
  • Find loops in everyday life: choruses in songs, stitches in knitting, laps of a track.
  • Deliberately write a loop with no stopping condition and discuss what would happen.

Frequently asked questions

What is a loop in coding?
An instruction that repeats a set of steps, either a fixed number of times or until a condition changes. It avoids writing the same instructions repeatedly.
What is an infinite loop?
A loop with no way to stop, so it repeats forever. It is a common bug, and discussing it helps children understand why a stopping condition matters.
How do loops relate to patterns?
Directly. Spotting that something repeats is what tells you a loop can be used, which is why pattern recognition is usually taught before loops.