Nested iteration: a loop inside a loop
A loop placed inside another loop. The inner loop completes all its repeats for every single repeat of the outer loop, so a 3 by 4 nest runs the inner body 12 times.
Understanding Nested iteration: a loop inside a loop in IGCSE Computer Science Paper 2
What it does: Day 1 runs Lap 1 to 3, then Day 2 runs Lap 1 to 3 again, giving 6 outputs. For each Player value the WHILE loop runs until its condition is false, then the FOR loop moves on to the next Player. The inner loop finishes all 4 repeats for each of the 3 repeats of the outer loop, so the totals are multiplied: 3 × 4 = 12. Day stays at 1 while Hour counts 1, 2, 3. Only then does Day become 2 and Hour starts again at 1. Loops must be properly nested, so the inner NEXT must come before the outer NEXT.
Common mistakes: The inner loop reuses the outer counter Row, so the two loops fight over the same variable. The inner loop needs its own counter name: FOR Col <- 1 TO 4. A FOR loop sets its counter with the assignment arrow <-, not =. The line should be FOR Num <- 1 TO 5.
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 389–398) and word search (Modules 379–398).
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 →