Revise Computing
Revision notesQuestionsFor schools
Log inStart revising free
Revision notesQuestionsFor schoolsLog in
GCSE Computer Science/Supplementary programming practice/Selection

Nested IF

301.9 Selection

Practise exam questions

Selection — Note 3 of 4

IF statements inside IF statements.

What you need to know

A nested if is an if statement inside another if statement. Use this when a second decision depends on the first. Indentation shows which if each else belongs to.

What to know

  • An if inside an if is 'nested'
  • The inner if only runs if the outer if is True
  • Indentation shows the nesting level
  • Don't nest too deeply — consider elif instead

Code examples

Nested IF
python
has_ticket = True
age = 14

if has_ticket:
    if age >= 18:
        print("Adult entry")
    else:
        print("Child entry")
else:
    print("Buy a ticket first")
← Previous noteELIF chains301.9 SelectionNext note →Match Case301.9 Selection

Back to Selection

Specification notes for programming are in Paper 2.

Selection

Note 3 of 4

  1. 1IF and Else
  2. 2ELIF chains
  3. 3Nested IF
  4. 4Match Case
Topic overview

© 2026 Revise Computing · revisecomputing.co.uk

Privacy noticeTermsContact

Revise Computing is an independent revision resource. It is not affiliated with, or endorsed by, OCR (Oxford Cambridge and RSA Examinations).