Tracing nested loops
A loop inside another loop. When tracing, the inner loop completes all its repeats for each single repeat of the outer loop, so total passes = outer repeats x inner repeats.
Understanding Tracing nested loops in VCE Software Development U3O1
What it does: i stays at 1 while j goes 1, 2, 3. Only after the inner loop finishes does i change to 2 and j restart at 1. The outer loop runs 6 times and the inner loop runs 2 times for each, so the print line runs 6 x 2 = 12 times. Correct trace: (1,1) (1,2) (1,3) then (2,1) (2,2) (2,3). That is 6 passes, not 3.
Common mistakes: The comment says there are 3 rows, so the outer loop must run 3 times. With 'to 2' it only runs twice, so row 3 is never traced. It should be 'for row from 1 to 3'. A counter must start at 0 before the loops. Starting at 1 makes the final count 13 instead of 4 x 3 = 12. It should be 'passes <- 0'.
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 168–177) and word search (Modules 168–193).
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
nested loopFill in the Blanks
Spot the Error
Student with a class code? Join your class →