← VCE Pseudocode

Nested for loops

A FOR loop placed entirely inside another FOR loop, so the inner loop runs fully for every repetition of the outer loop

Understanding Nested for loops in VCE Pseudocode

What it does: This description matches a nested FOR loop, where the inner loop runs to completion each time the outer loop advances. A nested loop is a complete FOR loop written inside the body of another FOR loop. Nested loops are commonly used to process grid-like structures, with one loop for rows and one for columns. Reusing the same loop variable for both loops causes a naming conflict.

Common mistakes: The inner loop reuses the outer loop's variable name row — it needs its own distinct variable, such as col. The outer FOR loop must be closed with END FOR, not END WHILE.

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 11–28) and word search (Modules 1–28).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Does a nested FOR loop place one FOR loop entirely inside another?
TrueFalse
Matches
FOR row FROM 1 TO 3 FOR row FROM 1 TO 2 DISPLAY row END FOR END FOR
↓
The inner loop should use a different variable name than the outer loop
Applying
Meanings
Term
Nested FOR loop
Meaning
A FOR loop placed entirely inside another FOR loop, so the inner loop runs fully for every repetition of the outer loop
Practice
BEGIN
Testing
Gaps
col FROM 1 TO 2
Check Answer
Spots
1FOR row FROM 1 TO 3
2 FOR row FROM 1 TO 2

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

The 'Cosmic Dragon' badge — Orbit Master, 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. Does a nested FOR loop place one FOR loop entirely inside another?
A. True ✓
B. False
A nested loop is a complete FOR loop written inside the body of another FOR loop.
2. Does the inner loop run fully for every single repetition of the outer loop?
A. False
B. True ✓
For each pass of the outer loop, the inner loop runs through its entire range before the outer loop continues.
3. Should the inner and outer loops use the same loop variable name?
A. False ✓
B. True
Each nested loop needs its own distinct loop variable to avoid conflicts.
4. Does each FOR loop in a nested structure need its own END FOR?
A. True ✓
B. False
Every FOR loop, whether inner or outer, must be closed with its own matching END FOR.
5. In a nested loop, which loop must be written first: the inner or the outer?
A. Inner
B. Outer ✓
The outer loop is written first, with the inner loop nested inside its body.

Match the Pairs

FOR row FROM 1 TO 3 FOR col FROM 1 TO 2 DISPLAY col END FOR END FOR → A nested FOR loop with an outer and inner loop, each with its own variable
Two matching END FOR keywords, one for each loop → Required to properly close both the inner and outer loops
A loop structure where the inner loop completes fully for each outer pass → Nested FOR loop
Distinct variables, such as row and col, used for the outer and inner loops → FOR row FROM 1 TO 3 FOR col FROM 1 TO 2
FOR row FROM 1 TO 3 FOR row FROM 1 TO 2 DISPLAY row END FOR END FOR → The inner loop should use a different variable name than the outer loop
FOR i FROM 1 TO 3 FOR j FROM 1 TO 2 DISPLAY j END FOR → A second END FOR is needed to close the outer loop as well

Key Term

Nested FOR loop
A FOR loop placed entirely inside another FOR loop, so the inner loop runs fully for every repetition of the outer loop

Fill in the Blanks

1. FOR row FROM 1 TO 3 FOR col FROM 1 TO 2
Hint: Type the keyword that starts the inner loop
2. FOR row FROM 1 TO 3 FOR col FROM 1 TO 2 DISPLAY col END FOR
Hint: Type the keywords that close the inner loop
3. FOR row FROM 1 TO 3 FOR col FROM 1 TO 2 DISPLAY col END FOR END FOR
Hint: Type the keywords that close the outer loop
4. FOR i FROM 1 TO 3 FOR j FROM 1 TO 2
Hint: Type a different variable name for the inner loop
5. The inner loop runs fully for each cycle of the outer loop
Hint: Type the word for a single pass through the outer loop

Spot the Error

Question 1
A FOR row FROM 1 TO 3
B FOR row FROM 1 TO 2
C DISPLAY row
D END FOR
E END FOR
Line B — The inner loop reuses the outer loop's variable name row — it needs its own distinct variable, such as col.
Question 2
A FOR i FROM 1 TO 3
B FOR j FROM 1 TO 2
C DISPLAY j
D END FOR
E END WHILE
Line E — The outer FOR loop must be closed with END FOR, not END WHILE.
Question 3
A FOR i FROM 1 TO 2
B FOR j FROM 1 TO 3
C PRINT i, j
D END FOR
E END FOR
Line C — VCAA pseudocode uses DISPLAY to output values, not PRINT.
Question 4
A FOR i FROM 1 TO 3
B FOR j FROM 1 TO 3
C DISPLAY i
D DISPLAY j
E END FOR
Line E — This closes only one loop — a second END FOR is needed to close the outer loop as well.
Question 5
A FOR x FROM 1 TO 4
B FOR y FROM 1 TO 2
C total <- total + x
D ENDFOR
E END FOR
Line D — The closing keyword should be written as END FOR, not ENDFOR.

Student with a class code? Join your class →