Computing · Stage 5

Nested Loops

Coding & Systems · repetition · use a loop inside a loop

✦ Computing📘 Stage 5 · S5⏱ ~12 min🧒 Ages 9–10★ Free to start
I can use a loop inside a loop.
Kavi the owl for Computing
📖

Kavi Fills the Window Boxes

Kavi had 3 window boxes to decorate, and wanted 4 flowers in each one. "I am NOT writing plant a flower twelve times!" hooted Kavi. So Kavi wrote a loop inside a loop: Repeat 3 times: [ Repeat 4 times: plant a flower ]. The outer loop counts the boxes; the inner loop fills each one. The inner loop runs all 4 flowers, then the outer loop moves to the next box and the inner loop runs again. "A loop inside a loop is a nested loop," said Kavi. "3 boxes, 4 flowers each — that is 3 × 4 = 12 flowers, from just two short lines!"

🎓

What your child will learn

1The parts of a loop inside a loopA nested loop is a loop inside another loop. The outer loop holds the inner loop, and the deepest action is the body. Tap each part to hear its job.
2A loop inside a loop, runningThis program fills 3 boxes with 4 flowers each. Press ▶ Run and watch the inner loop finish every box before the outer loop moves on.
3One loop, then a loop inside a loopA single loop repeats one action a few times. A nested loop wraps that whole loop inside another — so the counts multiply. Tap each card.
4Count the body-runsRead the nested loop, then say how many times the body runs. Reveal to check.
🔍

A peek inside

A nested loop: Repeat 2 times [ Repeat 5 times: beep ]. How many beeps in all?
the inner loop beeps 5 times; the outer loop repeats it 2 times → multiply 2 × 5

Try this at home: A loop placed inside another loop is called a ____ loop.

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.