The specification gives this exact example of nested iteration:
WHILE NotSolved
… Instructions here ...
FOR i ← 1 TO 5
… Instructions here …
ENDFOR
… Instructions here …
ENDWHILE
The rule that governs everything: the inner loop completes its FULL cycle for EVERY single iteration of the outer loop.
FOR row ← 1 TO 3
FOR col ← 1 TO 4
OUTPUT row, col
ENDFOR
ENDFOR
- Outer loop: 3 iterations
- Inner loop: 4 iterations each time
- Total outputs: 3 × 4 = 12
The order is: (1,1) (1,2) (1,3) (1,4) (2,1) (2,2) (2,3) (2,4) (3,1) (3,2) (3,3) (3,4).
Multiply to find the total. This is the standard exam calculation — and it links straight to 3.1.2, because nested loops are why bubble sort's work grows with roughly n × n.
Where nested iteration is genuinely needed
| Situation | Why nesting |
|---|
| Processing a 2D array (3.2.6) | Outer loop for rows, inner loop for columns |
| Printing a grid or times table | Outer for each line, inner for each item on the line |
| Bubble sort (3.1.4) | Outer for passes, inner for the pairs within a pass |
| Comparing every item with every other | Outer picks one, inner compares it to all the rest |
Nested loops with a validated input inside
Combining what you have learned so far — this is the shape of a high-tariff Paper 1 answer:
FOR student ← 1 TO 30
REPEAT
OUTPUT 'Enter mark (0-100)'
mark ← STRING_TO_INT(USERINPUT)
UNTIL mark ≥ 0 AND mark ≤ 100
total ← total + mark
ENDFOR
Here a definite outer loop (30 students, known) contains an indefinite inner loop (validation, unknown attempts). Choosing the right loop type for each level is precisely the judgement examiners are testing.
AQA tip. Indentation is not decoration here — with two or three levels of nesting, an unindented answer becomes genuinely unmarkable. Indent every level by a consistent amount and make sure each ENDFOR/ENDWHILE lines up with its opening statement.