Computing · Stage 5

Challenge: Nested-Loop Patterns

Thinking It Through · nested loops · reason about a loop inside a loop

✦ Computing📘 Stage 5 · S5⏱ ~12 min🧒 Ages 9–10★ Free to start
I can reason about nested loops.
Kavi the owl for Computing
📖

Kavi and the Stadium of Lights

Kavi looked up at a huge scoreboard made of tiny lights — 8 rows, with 10 lights in each row. "How many lights is that?" a young owl asked. Kavi smiled and pointed at a short program on the wall: Repeat 8 times [ Repeat 10 times: switch on a light ]. "Count them one by one and you will be here all night," Kavi hooted. "But a nested loop does the thinking: the inner loop lights up all 10 in a row, and the outer loop does that for each of the 8 rows. So you don't add — you multiply: 8 × 10 = 80 lights." Kavi's eyes sparkled. "The real challenge isn't lighting them up — it's being able to reason about any loop inside a loop: how many, how deep, and what runs most."

🎓

What your child will learn

1Outer, inner, body — and the totalIn a nested loop, one loop sits inside another. To reason about it, name the three parts, then MULTIPLY the repeat counts to find how many times the deepest action runs. Tap each part.
2A loop inside a loop lighting a gridThis program lights a grid of 3 rows with 4 lights each. Press ▶ Run — watch the inner loop finish a whole row before the outer loop starts the next one.
3The trap: adding instead of multiplyingThe commonest mistake with nested loops is to ADD the two counts. But the inner loop runs fully for EACH outer turn, so the counts multiply. Tap each card.
🔍

A peek inside

A nested loop: Repeat 6 times [ Repeat 7 times: switch on a light ]. How many lights in all?
the inner loop lights 7, and the outer loop repeats that 6 times → multiply 6 × 7

Try this at home: In a nested loop, to find how many times the body runs you ____ the two repeat counts.

Ready to play and learn?

Start the free interactive lesson, or print the handout for screen-free play.

Part of Computing · Stage 5 · S5 on KAVI Academy — a secular, whole-child learning platform for ages 5–12.