Nested selection: an IF inside an IF
An IF placed inside the THEN or ELSE branch of another IF. It is only checked when that outer branch runs, and each IF needs its own ENDIF, with the inner ENDIF written first.
Understanding Nested selection: an IF inside an IF in IGCSE Computer Science Paper 2
What it does: Each level of IF is indented further in, so the student can see which ENDIF closes which IF. Checking Age >= 13 and then HasTicket = TRUE in a nested IF gives the same result as joining the two conditions with AND. An inner IF is part of the outer THEN or ELSE branch. If that branch is not chosen, the inner condition is never tested. The inner IF is closed first because it sits inside the outer IF. Each IF needs its own ENDIF. Every IF needs its own ENDIF, so two IFs need two ENDIFs. One ENDIF cannot close both.
Common mistakes: The inner IF has the operator written the wrong way round. 'Greater than or equal to' is >=, not =>. It should be IF mark >= 80 THEN. The inner IF is missing THEN. Every IF, including a nested one, must end its condition with THEN. It should be IF age < 12 THEN.
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 IFFill in the Blanks
Spot the Error
Student with a class code? Join your class →