← VCE Pseudocode

Nested and mixed iteration

Nesting one loop type inside a different loop type, such as a FOR loop inside a WHILE loop

Understanding Nested and mixed iteration in VCE Pseudocode

What it does: This description matches mixed iteration, combining different loop types together. A FOR loop must close with END FOR, and a WHILE loop must close with END WHILE, regardless of nesting. Just like same-type nested loops, the inner loop completes fully before the outer loop advances. Loops can be nested multiple levels deep, combining FOR, WHILE, and REPEAT-UNTIL as needed. ENDFOR written as one word is incorrect — VCAA pseudocode uses END FOR as two words. The inner WHILE loop is missing its own END WHILE, so the structure is not properly closed.

Common mistakes: The outer WHILE loop must be closed with END WHILE, not END LOOP. VCAA pseudocode uses DISPLAY to output a value, not PRINT.

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
Can a FOR loop be nested inside a WHILE loop?
TrueFalse
Matches
WHILE total < 10 DO FOR i FROM 1 TO 3 total ← total + i ENDFOR END WHILE
↓
The inner loop should close with END FOR, not ENDFOR
Applying
Meanings
Term
Mixed iteration
Meaning
Nesting one loop type inside a different loop type, such as a FOR loop inside a WHILE loop
Practice
BEGIN
Testing
Gaps
i FROM 1 TO 3
Check Answer
Spots
4 END FOR
5END LOOP

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

The 'Platinum Fox' badge — Tundra Legend, 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. Can a FOR loop be nested inside a WHILE loop?
A. False
B. True ✓
Mixed iteration allows a FOR loop to be placed entirely inside a WHILE loop, or vice versa.
2. Does each nested loop need its own matching closing keyword?
A. True ✓
B. False
A FOR loop must close with END FOR, and a WHILE loop must close with END WHILE, regardless of nesting.
3. In mixed iteration, does the inner loop run fully for each repetition of the outer loop?
A. False
B. True ✓
Just like same-type nested loops, the inner loop completes fully before the outer loop advances.
4. Can a WHILE loop be nested inside a FOR loop?
A. True ✓
B. False
Mixed iteration also allows a WHILE loop to be nested inside a FOR loop.
5. If a FOR loop is nested inside a WHILE loop, should it close with END WHILE?
A. False ✓
B. True
The inner FOR loop must close with END FOR — closing keywords always match their own loop type.

Match the Pairs

WHILE total < 10 DO FOR i FROM 1 TO 3 total ← total + i END FOR END WHILE → A FOR loop nested inside a WHILE loop
END FOR followed by END WHILE → Closes the inner FOR loop first, then the outer WHILE loop
Nesting one loop type inside a different loop type → Mixed iteration
A WHILE loop written entirely inside the body of a FOR loop → FOR j FROM 1 TO 5 WHILE total < 20 DO
WHILE total < 10 DO FOR i FROM 1 TO 3 total ← total + i ENDFOR END WHILE → The inner loop should close with END FOR, not ENDFOR
FOR i FROM 1 TO 3 WHILE total < 5 DO total ← total + i END FOR → The inner WHILE loop must be closed with END WHILE before END FOR

Key Term

Mixed iteration
Nesting one loop type inside a different loop type, such as a FOR loop inside a WHILE loop

Fill in the Blanks

1. WHILE total < 10 DO FOR i FROM 1 TO 3
Hint: Type the keyword that starts the inner loop
2. WHILE total < 10 DO FOR i FROM 1 TO 3 total ← total + i END FOR
Hint: Type the keywords that close the inner FOR loop
3. WHILE total < 10 DO FOR i FROM 1 TO 3 total ← total + i END FOR END WHILE
Hint: Type the keywords that close the outer WHILE loop
4. FOR j FROM 1 TO 5 WHILE total < 20 DO
Hint: Type the keyword that starts the inner loop when nesting WHILE inside FOR
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 WHILE total < 10 DO
B FOR i FROM 1 TO 3
C total ← total + i
D END FOR
E END LOOP
Line E — The outer WHILE loop must be closed with END WHILE, not END LOOP.
Question 2
A FOR j FROM 1 TO 5
B WHILE total < 20 DO
C PRINT total
D total ← total + 1
E END WHILE
F END FOR
Line C — VCAA pseudocode uses DISPLAY to output a value, not PRINT.
Question 3
A WHILE count < 5 DO
B FOR k FROM 1 TO 2
C count ← count + 1
D ENDFOR
E END WHILE
Line D — The closing keyword for the inner loop should be written as END FOR, not ENDFOR.
Question 4
A FOR i FROM 1 TO 3
B WHILE total < 15
C total ← total + i
D END WHILE
E END FOR
Line B — The WHILE condition is missing DO — it should read WHILE total < 15 DO.
Question 5
A total ← 0
B WHILE total < 10 DO
C FOR i FROM 1 TO 3
D total = total + i
E END FOR
F END WHILE
Line D — Assignment in pseudocode uses ←, not =.

Student with a class code? Join your class →