← IGCSE Computer Science Paper 2

IF…THEN…ENDIF (7d)

Runs the indented lines between THEN and ENDIF only when the condition is TRUE. If it is FALSE, those lines are skipped. Every IF must be closed with its own ENDIF.

Understanding IF…THEN…ENDIF (7d) in IGCSE Computer Science Paper 2

What it does: The OUTPUT line is indented under THEN, showing it belongs to the IF and runs only when Age >= 18 is TRUE. Count is 0, so Count > 5 is FALSE. OUTPUT "Big" is skipped and the program carries on to OUTPUT "Done" after ENDIF. Every IF ... THEN must be closed with its own ENDIF. Plain END is not used for IF. The second version has no ENDIF, so the IF is never closed. Indenting the THEN lines makes it clear which statements are controlled by the condition. Count = 0 is TRUE, so the assignment inside the IF runs and Count becomes 1.

Common mistakes: The IF line is missing the keyword THEN. The condition must be followed by THEN: IF score >= 50 THEN. The ← symbol assigns a value. A condition needs a comparison operator, so it should be IF temp = 30 THEN.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

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 265–274) and word search (Modules 254–274).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which line must close every IF statement in Cambridge pseudocode?
ENDENDIF
Matches
IF Temp > 30 THEN OUTPUT "Hot"
↓
The IF has no ENDIF. Every IF must be closed with ENDIF after the lines that depend on the condition.
Applying
Meanings
Term
IF condition THEN ... ENDIF
Meaning
Runs the indented lines between THEN and ENDIF only when the condition is TRUE. If it is FALSE, those lines are skipped. Every IF must be closed with its own ENDIF.
Practice
INPUT Mark
Testing
Gaps
Age >= 16 THEN
Check Answer
Spots
1IF score >= 50
2 OUTPUT "Pass"

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Desert Jerboa' badge — High Jumper, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which line must close every IF statement in Cambridge pseudocode?
A. ENDIF ✓
B. END
Every IF ... THEN must be closed with its own ENDIF. Plain END is not used for IF.
2. Score ← 40. IF Score > 50 THEN OUTPUT "Pass" ENDIF. What is output?
A. Pass
B. Nothing is output ✓
40 > 50 is FALSE, so the lines between THEN and ENDIF are skipped and nothing is output.
3. Which IF statement is written correctly?
A. IF Age >= 18 THEN OUTPUT "Adult"
B. IF Age >= 18 THEN OUTPUT "Adult" ENDIF ✓
The second version has no ENDIF, so the IF is never closed.
4. Temp ← 35. IF Temp > 30 THEN OUTPUT "Hot" ENDIF. What is output?
A. Hot ✓
B. Nothing is output
35 > 30 is TRUE, so the indented line between THEN and ENDIF runs and Hot is output.
5. When does the code between THEN and ENDIF run?
A. Only when the condition is TRUE ✓
B. Every time, whatever the condition is
An IF without ELSE runs its lines only when the condition is TRUE. If it is FALSE, they are skipped.

Match the Pairs

IF Score >= 50 THEN OUTPUT "Pass" ENDIF → Outputs Pass only when Score is 50 or more; if Score is lower, the OUTPUT line is skipped
ENDIF → Closes the IF statement and marks where the conditional lines end
The lines between THEN and ENDIF are indented so it is clear which lines depend on the condition → IF Age >= 18 THEN OUTPUT "Adult" ENDIF
When the condition is FALSE, the program skips the indented lines and carries on after ENDIF → Count ← 0 IF Count > 5 THEN OUTPUT "Big" ENDIF OUTPUT "Done"
IF Temp > 30 THEN OUTPUT "Hot" → The IF has no ENDIF. Every IF must be closed with ENDIF after the lines that depend on the condition.
IF Score > 90 THEN OUTPUT "Top mark" ENDIF → The line between THEN and ENDIF is not indented, so it is not clear that it depends on the condition.

Key Term

IF condition THEN ... ENDIF
Runs the indented lines between THEN and ENDIF only when the condition is TRUE. If it is FALSE, those lines are skipped. Every IF must be closed with its own ENDIF.

Fill in the Blanks

1. IF Age >= 16 THEN OUTPUT "Adult" ENDIF
Hint: Type the keyword that starts a selection and is followed by a condition.
2. IF Score > 50 THEN OUTPUT "Pass" ENDIF
Hint: Type the keyword that comes after the condition and before the lines that run when it is TRUE.
3. IF Temp < 10 THEN OUTPUT "Cold" ENDIF
Hint: Type the keyword that closes the IF block, so the program knows where the skipped or run lines end.
4. IF Total > 100 THEN Discount ← 10 ENDIF
Hint: Type the comparison operator meaning strictly greater than.
5. IF Count > 0 THEN OUTPUT Total / Count ENDIF
Hint: Type the command that displays a value. This indented line only runs when the condition is TRUE.

Spot the Error

Question 1
A IF score >= 50
B OUTPUT "Pass"
C ENDIF
Line A — The IF line is missing the keyword THEN. The condition must be followed by THEN: IF score >= 50 THEN.
Question 2
A IF temp ← 30 THEN
B OUTPUT "Exactly 30"
C ENDIF
Line A — The ← symbol assigns a value. A condition needs a comparison operator, so it should be IF temp = 30 THEN.
Question 3
A total ← 0
B IF total == 0 THEN
C OUTPUT "Empty"
D ENDIF
Line B — Cambridge pseudocode compares with a single =, not ==. The line should be IF total = 0 THEN.
Question 4
A INPUT age
B IF age >= 18 THEN
C OUTPUT "Adult"
D ENDWHILE
Line D — An IF must be closed with ENDIF. ENDWHILE closes a WHILE loop, so the last line should be ENDIF.
Question 5
A INPUT mark
B IF mark < 40 THEN
C PRINT "Retake"
D ENDIF
Line C — Cambridge pseudocode uses OUTPUT to display a value, not PRINT. The indented line inside the IF should be OUTPUT "Retake".

Student with a class code? Join your class →