← ACARA Digital Technologies Years 7–8

A loop inside a loop

A REPEAT placed inside another REPEAT. The inner loop runs all its repeats again for every repeat of the outer loop, so an outer 3 and an inner 4 gives 12 inner passes.

Understanding A loop inside a loop in ACARA Digital Technologies Years 7–8

What it does: The inner loop is indented one level further, and the two END REPEAT lines close the inner loop first and then the outer loop. For each of the 4 rows, the inner loop checks 3 seats, so there are 4 x 3 = 12 checks in total. A nested loop sits inside the body of another loop. Two loops one after the other are just in sequence. Indenting each loop body shows which steps belong to which loop. Pseudocode with everything at the left edge is hard to read. Multiply the outer count by the inner count: 5 x 2 = 10 inner passes.

Common mistakes: The outer loop must say how many repeats it makes using the word TIMES. It should be 'REPEAT 3 TIMES'. The inner loop has the words in the wrong order. A counted loop is written REPEAT then the number then TIMES, so it should be ' REPEAT 4 TIMES'.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 365–411) and word search (Modules 331–411).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
An outer REPEAT 3 TIMES has an inner REPEAT 4 TIMES. How many times does the inner step run in total?
12 times7 times
Matches
REPEAT 3 TIMES REPEAT 4 TIMES SAY "Hi" END REPEAT
↓
There is only one END REPEAT for two loops. Each loop needs its own END REPEAT, so a second one is missing.
Applying
Meanings
Term
nested loop
Meaning
A REPEAT placed inside another REPEAT. The inner loop runs all its repeats again for every repeat of the outer loop, so an outer 3 and an inner 4 gives 12 inner passes.
Practice
REPEAT 3 TIMES
Testing
Gaps
4 TIMES
Check Answer
Spots
1REPEAT 3
2 REPEAT 4 TIMES

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Sperm Whale' badge — Deep Sea Champion, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. An outer REPEAT 3 TIMES has an inner REPEAT 4 TIMES. How many times does the inner step run in total?
A. 12 times ✓
B. 7 times
The inner loop runs all 4 repeats for each of the 3 outer repeats, so 3 x 4 = 12, not 3 + 4.
2. Which statement describes a nested loop correctly?
A. A REPEAT placed inside another REPEAT ✓
B. Two REPEATs written one after the other
A nested loop sits inside the body of another loop. Two loops one after the other are just in sequence.
3. Each time the outer loop repeats once, what does the inner loop do?
A. It runs only once
B. It runs all of its repeats again ✓
The inner loop starts fresh and completes every one of its repeats for each outer repeat.
4. Which layout shows both loops indented correctly? A: REPEAT 2 TIMES, then the inner REPEAT indented, then its step indented twice B: REPEAT 2 TIMES, then the inner REPEAT, then its step, all at the left edge
A. A ✓
B. B
Indenting each loop body shows which steps belong to which loop. Pseudocode with everything at the left edge is hard to read.
5. How many END REPEAT lines does an algorithm with two nested loops need?
A. One, shared by both loops
B. Two, one for each REPEAT ✓
Every REPEAT needs its own END REPEAT. The first one closes the inner loop and the second closes the outer loop.

Match the Pairs

REPEAT 3 TIMES REPEAT 4 TIMES SAY "Hi" → The inner loop runs 4 times for each of the 3 outer repeats, so Hi is said 12 times.
REPEAT 2 TIMES REPEAT 5 TIMES SAY "Go" → The inner loop runs 5 times for each of the 2 outer repeats, so Go is said 10 times.
Both loops are indented so you can see which loop sits inside the other, and each loop is closed with its own END REPEAT. → REPEAT 3 TIMES REPEAT 2 TIMES SAY "Step" END REPEAT END REPEAT
The inner loop is a complete REPEAT that starts over for each outer repeat, like 4 rows of 3 seats gives 12 seat checks. → REPEAT 4 TIMES REPEAT 3 TIMES CHECK SEAT END REPEAT END REPEAT
REPEAT 3 TIMES REPEAT 4 TIMES SAY "Hi" END REPEAT → There is only one END REPEAT for two loops. Each loop needs its own END REPEAT, so a second one is missing.
REPEAT 3 TIMES REPEAT 4 TIMES SAY "Hi" END REPEAT END REPEAT → Nothing is indented, so it is hard to see that the inner loop sits inside the outer loop. Both loops should be indented.

Key Term

nested loop
A REPEAT placed inside another REPEAT. The inner loop runs all its repeats again for every repeat of the outer loop, so an outer 3 and an inner 4 gives 12 inner passes.

Fill in the Blanks

1. REPEAT 3 TIMES REPEAT 4 TIMES PRINT "*"
Hint: Type the keyword that starts the inner loop, placed inside the outer loop.
2. SET outer ← 3 SET inner ← 4 SET passes ← outer * inner
Hint: Type the operator that works out the total inner passes from the outer and inner repeat counts.
3. PRINT "*" END REPEAT END REPEAT
Hint: Type the line that closes the inner loop before the outer loop is closed.
4. REPEAT 2 TIMES REPEAT 5 TIMES PRINT "ping" // 10 pings in all
Hint: Type the inner repeat count that gives the total shown in the comment when multiplied by the outer count.
5. REPEAT 3 TIMES REPEAT 4 TIMES PRINT "x" // 12 inner passes in all
Hint: Type the outer repeat count that, multiplied by the inner count, gives the total in the comment.

Spot the Error

Question 1
A REPEAT 3
B REPEAT 4 TIMES
C OUTPUT "*"
D END REPEAT
E END REPEAT
Line A — The outer loop must say how many repeats it makes using the word TIMES. It should be 'REPEAT 3 TIMES'.
Question 2
A REPEAT 3 TIMES
B REPEAT TIMES 4
C ADD 1 TO total
D END REPEAT
E END REPEAT
Line B — The inner loop has the words in the wrong order. A counted loop is written REPEAT then the number then TIMES, so it should be ' REPEAT 4 TIMES'.
Question 3
A REPEAT 2 TIMES
B REPEAT UNTIL 5 TIMES
C OUTPUT "x"
D END REPEAT
E END REPEAT
Line B — This mixes two kinds of loop. A set-count loop is written REPEAT 5 TIMES. REPEAT UNTIL needs a condition, not a number of times.
Question 4
A REPEAT 3 TIMES
B REPEAT 4 TIMES
C OUTPUT "*"
D END IF
E END REPEAT
Line D — The inner loop is closed with END REPEAT, not END IF. Line 4 should be ' END REPEAT'.
Question 5
A REPEAT 3 TIMES
B OUTPUT "Row"
C REPEAT 4 STEPS
D OUTPUT "*"
E END REPEAT
F END REPEAT
Line C — A counted loop uses the keyword TIMES, not STEPS. The inner loop should be ' REPEAT 4 TIMES'.

Student with a class code? Join your class →