Tracing a decision inside a loop
Trace an IF inside a loop with one row for each pass, showing the condition result (true or false) and any variables that change. The final row gives the output.
Understanding Tracing a decision inside a loop in ACARA Digital Technologies Years 7–8
What it does: The condition n > 2 is tested once per pass, giving a different result in each row: false, false, true, true. The OUTPUT line runs after the loop ends, so the final row shows the finished value of total, 9. Give each pass of the loop its own row. This lets you see exactly what changed each time. 3 is greater than 2, so the condition is TRUE. The IF block runs and count goes from 0 to 1. A variable keeps its value when the IF block is skipped. Copy the old value down so the next row starts correctly.
Common mistakes: The counter must start at 0. Starting at 1 means the final row shows 3 instead of the correct 2 (only i = 4 and i = 5 pass the test). It should be count ← 0. With < 5 the loop stops after pass 4, so one row is missing from the trace. It should be WHILE pass <= 5 so that pass 5 also gets its own row.
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.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
one row per passFill in the Blanks
Spot the Error
Student with a class code? Join your class →