← ACARA Digital Technologies Years 7–8

Error: a step placed inside or outside the loop

A bug where a step sits in the wrong place around a loop. A SHOW inside repeats every pass, and an update outside runs only once. Indentation shows which steps are inside the loop.

Understanding Error: a step placed inside or outside the loop in ACARA Digital Technologies Years 7–8

What it does: Here SHOW is not indented, so it sits outside the loop and runs once after all the passes have finished. i ← i + 1 is outside the loop, so i stays 1 and the condition is always true. Indent the update into the loop.

Common mistakes: The update is not indented, so it sits outside the loop and runs only once. It should be ' ADD 1 TO sides', indented inside the loop, so sides grows on every pass. The score update is at the left margin, so it is outside the loop and runs only once. It should be ' ADD 2 TO score', indented inside the loop, so it repeats on every pass.

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 420–481) and word search (Modules 420–519).

Take this worksheet further — free with Cloodit

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

Learning
Duo
total ← 0 REPEAT 5 TIMES total ← total + 2 SHOW total The goal is to show only the final total. What is the problem?
SHOW is outside the loop, so it prints only onceSHOW is inside the loop, so it prints on every pass
Matches
SET total TO 0 REPEAT 4 TIMES SET total TO total + 5 SHOW total
↓
SHOW is inside the loop, so it prints 5, 10, 15, 20 instead of only the final total of 20. Fix: un-indent SHOW so it is after the loop.
Applying
Meanings
Term
loop placement error
Meaning
A bug where a step sits in the wrong place around a loop. A SHOW inside repeats every pass, and an update outside runs only once. Indentation shows which steps are inside the loop.
Practice
total ← 0
Testing
Gaps
total
Check Answer
Spots
1REPEAT 4 TIMES
2SET sides TO sides + 1

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

The 'Giant Isopod' badge — Patient Builder, 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. total ← 0 REPEAT 5 TIMES total ← total + 2 SHOW total The goal is to show only the final total. What is the problem?
A. SHOW is outside the loop, so it prints only once
B. SHOW is inside the loop, so it prints on every pass ✓
SHOW is indented, so it is inside the loop. It prints 2, 4, 6, 8, 10 instead of just 10. Move SHOW out and unindent it.
2. Which line shows a step that runs only ONCE after the loop finishes?
A. SHOW total (indented under the loop)
B. SHOW total (not indented, below the loop) ✓
Indentation shows what is inside the loop. A line that is not indented sits outside the loop and runs once, after the loop ends.
3. count ← 0 REPEAT 4 TIMES SHOW "Hi" count ← count + 1 The goal is to count each pass. What is the bug?
A. The update is outside the loop, so count only goes up once ✓
B. The update is inside the loop, so count goes up too often
count ← count + 1 is not indented, so it runs once after the loop. Indent it so it runs on every pass.
4. True or false: indentation helps you see which steps are inside a loop.
A. True ✓
B. False
Indented lines under REPEAT or WHILE are inside the loop body. Lines lined up with REPEAT are outside it.
5. A student wants a welcome message printed once, but writes it indented inside a loop. What happens?
A. The message repeats on every pass of the loop ✓
B. The message prints once before the loop starts
A step inside the loop runs every time the loop repeats. A message meant to run once belongs outside the loop.

Match the Pairs

REPEAT 5 TIMES SET total TO total + 2 SHOW total → SHOW is indented inside the loop, so it prints total on every pass (5 lines) instead of once at the end.
SET count TO 0 WHILE count < 3 SHOW count SET count TO count + 1 → The update is outside the loop because it is not indented, so it never runs inside the loop and the loop never stops.
To print the total only once, put SHOW after the loop, lined up with REPEAT and not indented. → REPEAT 5 TIMES SET total TO total + 2 SHOW total
A step that must happen on every pass, like adding to a total, must be indented inside the loop. → FOR each mark IN marks SET total TO total + mark SHOW total
SET total TO 0 REPEAT 4 TIMES SET total TO total + 5 SHOW total → SHOW is inside the loop, so it prints 5, 10, 15, 20 instead of only the final total of 20. Fix: un-indent SHOW so it is after the loop.
SET n TO 1 REPEAT UNTIL n > 3 SHOW n SET n TO n + 1 → The update SET n TO n + 1 is outside the loop, so n never changes and the loop runs forever. Fix: indent it so it is inside the loop.

Key Term

loop placement error
A bug where a step sits in the wrong place around a loop. A SHOW inside repeats every pass, and an update outside runs only once. Indentation shows which steps are inside the loop.

Fill in the Blanks

1. REPEAT 5 TIMES total ← total + 2 SHOW total
Hint: Type the keyword that displays the value once, after the loop has finished (not indented).
2. REPEAT 4 TIMES count ← count + 1 SHOW count
Hint: Type the variable that must be updated inside the loop so it changes on every pass.
3. REPEAT 3 TIMES SHOW "Go!" SHOW "Done"
Hint: Type the keyword that starts the loop, so the indented SHOW repeats and the last SHOW runs once.
4. REPEAT UNTIL count = 3 count ← count + 1 SHOW count
Hint: Type the keyword that keeps the loop going until its condition becomes true.
5. REPEAT 3 TIMES total ← total + 5 SHOW total
Hint: Type the variable being shown on every pass because the SHOW is indented inside the loop.

Spot the Error

Question 1
A REPEAT 4 TIMES
B SET sides TO sides + 1
C TURN RIGHT 90
D SHOW sides
Line B — The update is not indented, so it sits outside the loop and runs only once. It should be ' ADD 1 TO sides', indented inside the loop, so sides grows on every pass.
Question 2
A REPEAT 3 TIMES
B SET score TO score + 2
C SHOW score
Line B — The score update is at the left margin, so it is outside the loop and runs only once. It should be ' ADD 2 TO score', indented inside the loop, so it repeats on every pass.
Question 3
A SET count TO 0
B WHILE count < 3
C SET count TO count + 1
D SHOW count
Line C — The update is not indented, so it is outside the loop. count never changes inside the WHILE loop, so the loop never stops. It should be ' ADD 1 TO count', indented inside the loop.
Question 4
A SHOW "Counting..."
B REPEAT 3 TIMES
C ADD 1 TO count
D SHOW count
Line A — This message is indented as if it belonged to a loop. A one-off opening message should sit at the left margin, before the loop, so it is shown once. It should be 'SHOW "Counting starts"' with no indent.
Question 5
A REPEAT 3 TIMES
B MOVE 10 STEPS
C SHOW "Step taken"
Line C — The indent puts SHOW inside the loop, so it prints on every pass. The arrival message should appear once, after the loop. It should be 'SHOW "Arrived"' with no indent.

Student with a class code? Join your class →