← IGCSE Computer Science Paper 2

IF…THEN…ELSE…ENDIF (7d)

Starts the lines that run when the IF condition is FALSE. Exactly one branch runs: THEN or ELSE, never both. ELSE has no condition of its own.

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

What it does: The ELSE line is written on its own with no test after it. It runs automatically whenever Age >= 16 is FALSE. A number is either even or odd, so the condition is TRUE or FALSE. This means one of the two outputs always happens and the other is skipped. ELSE has no condition of its own. It just means 'otherwise'. Only IF (and ELSE IF) test a condition. There is no ENDELSE. The ELSE lines sit inside the IF structure, and a single ENDIF closes it.

Common mistakes: ELSE has no condition of its own. It runs automatically when the IF condition is FALSE. The line should be just ELSE. The THEN branch runs when Mark >= 50 is TRUE, so it should output "Pass". Outputting "Fail" there gives the wrong message. The line should be OUTPUT "Pass".

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
The IF condition is FALSE. Which lines run?
The lines after THENThe lines after ELSE
Matches
IF Mark >= 50 THEN OUTPUT "Pass" ELSE Mark < 50 THEN OUTPUT "Fail" ENDIF
↓
ELSE was given its own condition and THEN. ELSE never has a condition. It should be written on its own line as just ELSE.
Applying
Meanings
Term
ELSE
Meaning
Starts the lines that run when the IF condition is FALSE. Exactly one branch runs: THEN or ELSE, never both. ELSE has no condition of its own.
Practice
IF Mark >= 50 THEN
Testing
Gaps
OUTPUT "Fail"
Check Answer
Spots
2 OUTPUT "Hot"
3ELSE Temp <= 30

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

The 'Hippopotamus' badge — Savannah Titan, 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. The IF condition is FALSE. Which lines run?
A. The lines after ELSE ✓
B. The lines after THEN
When the condition is FALSE, the THEN lines are skipped and the lines after ELSE run instead.
2. In IF...THEN...ELSE...ENDIF, how many branches run each time?
A. Exactly one: THEN or ELSE ✓
B. Both THEN and ELSE
Exactly one branch runs. If the condition is TRUE the THEN lines run. If it is FALSE the ELSE lines run. Never both.
3. Which is the correct way to write the ELSE line?
A. ELSE score < 50
B. ELSE ✓
ELSE has no condition of its own. It just means 'otherwise'. Only IF (and ELSE IF) test a condition.
4. mark ← 40 IF mark >= 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail" ENDIF What is output?
A. Pass
B. Fail ✓
40 >= 50 is FALSE, so the THEN branch is skipped and the ELSE branch outputs Fail.
5. age ← 18 IF age < 18 THEN OUTPUT "Child" ELSE OUTPUT "Adult" ENDIF What is output?
A. Adult ✓
B. Child
18 < 18 is FALSE because 18 is not less than 18. So the ELSE branch runs and outputs Adult.

Match the Pairs

IF Mark >= 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail" ENDIF → Outputs Pass if Mark is 50 or more, otherwise outputs Fail. Exactly one of the two lines runs.
ELSE IF Score >= 40 THEN → Adds a second condition that is only checked when the first IF condition was FALSE.
ELSE has no condition of its own. It simply runs when the IF condition is FALSE. → IF Age >= 16 THEN OUTPUT "Allowed" ELSE OUTPUT "Not allowed" ENDIF
Exactly one branch runs: THEN or ELSE, never both and never neither. → IF Number MOD 2 = 0 THEN OUTPUT "Even" ELSE OUTPUT "Odd" ENDIF
IF Mark >= 50 THEN OUTPUT "Pass" ELSE Mark < 50 THEN OUTPUT "Fail" ENDIF → ELSE was given its own condition and THEN. ELSE never has a condition. It should be written on its own line as just ELSE.
IF Mark >= 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail" → The ENDIF is missing. Every IF...THEN...ELSE structure must be closed with ENDIF.

Key Term

ELSE
Starts the lines that run when the IF condition is FALSE. Exactly one branch runs: THEN or ELSE, never both. ELSE has no condition of its own.

Fill in the Blanks

1. IF Mark >= 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail" ENDIF
Hint: Type the keyword that starts the lines that run when the condition is FALSE. It has no condition of its own.
2. IF Temp > 30 THEN OUTPUT "Hot" ELSE OUTPUT "Not hot" ENDIF
Hint: Type the keyword that comes after the condition and starts the lines that run when it is TRUE.
3. IF Score >= 70 THEN OUTPUT "A" ELSE IF Score >= 50 THEN OUTPUT "B" ELSE OUTPUT "C" ENDIF
Hint: Type the keyword that follows ELSE to add a second condition to the chain.
4. IF Stock < 5 THEN OUTPUT "Reorder" ELSE OUTPUT "Stock OK" ENDIF
Hint: Type the comparison operator that means 'less than'.
5. IF Pin = Code THEN OUTPUT "Open" ELSE OUTPUT "Locked" ENDIF
Hint: Type the keyword that closes the whole IF structure after the ELSE branch.

Spot the Error

Question 1
A IF Temp > 30 THEN
B OUTPUT "Hot"
C ELSE Temp <= 30
D OUTPUT "Cool"
E ENDIF
Line C — ELSE has no condition of its own. It runs automatically when the IF condition is FALSE. The line should be just ELSE.
Question 2
A INPUT Mark
B IF Mark >= 50 THEN
C OUTPUT "Fail"
D ELSE
E OUTPUT "Fail"
F ENDIF
Line C — The THEN branch runs when Mark >= 50 is TRUE, so it should output "Pass". Outputting "Fail" there gives the wrong message. The line should be OUTPUT "Pass".
Question 3
A INPUT Num
B IF Num MOD 2 = 0 THEN
C OUTPUT "Even"
D ELSE THEN
E OUTPUT "Odd"
F ENDIF
Line D — THEN belongs only after the IF condition. ELSE has no condition and no THEN. The line should be just ELSE.
Question 4
A INPUT Age
B IF Age >= 13
C OUTPUT "Allowed"
D ELSE
E OUTPUT "Too young"
F ENDIF
Line B — The IF line must end with THEN. It should be IF Age >= 13 THEN.
Question 5
A IF Mark >= 70 THEN
B OUTPUT "Merit"
C ELSE Mark >= 50 THEN
D OUTPUT "Pass"
E ENDIF
Line C — ELSE has no condition of its own. To test a second condition in a chain you need ELSE IF. The line should be ELSE IF Mark >= 50 THEN.

Student with a class code? Join your class →