Nested loops: a loop inside a loop
A loop inside another loop. The inner loop runs all its repeats for every single repeat of the outer loop, so an outer 3 and inner 4 gives 12 passes.
Understanding Nested loops: a loop inside a loop in ACARA Digital Technologies Years 7–8
What it does: The inner loop builds one full row of 4 stars each time, and the outer loop repeats this for 3 rows, so the inner loop runs all its repeats for every outer repeat. Using a different counter name for the inner loop (j) keeps the two counters from getting mixed up. A multiplication grid multiplies the row number by the column number, so use i * j. Paired symbols must match. Two nested loops have two opening braces, so an extra closing brace is a syntax error.
Common mistakes: The inner loop reuses the counter name i, which clashes with the outer loop's counter. Give it its own name: for (let j=0; j<4; j++). The outer loop counts down with i-- but the condition i<3 stays true, so it never ends. It should be i++ so the outer loop repeats 3 times.
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 599–610) and word search (Modules 583–613).
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 →