Three levels of nesting
Putting one structure inside another, three levels deep. Indent each level and close them in reverse order: innermost first, e.g. ENDIF, ENDIF, then NEXT.
Understanding Three levels of nesting in IGCSE Computer Science Paper 2
What it does: The IF is innermost so ENDIF comes first. The FOR is in the middle so NEXT comes next. The WHILE is outermost so ENDWHILE comes last. The FOR is at level 1, the first IF is indented to level 2, the second IF to level 3, and the OUTPUT sits inside all three. Each nested structure is indented one more level, so you can see which structure owns which lines. Closing statements are written in reverse order of opening: IF opened last, so it closes first. Understand the innermost structure first, then see how the structures around it control when it runs.
Common mistakes: The outer IF is missing THEN. Every IF condition must end with THEN, so the line should be IF Rain > 10 THEN. A WHILE loop uses DO, not THEN. THEN belongs to IF. The line should be WHILE Total < 100 DO.
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
nestingFill in the Blanks
Spot the Error
Student with a class code? Join your class →