← IGCSE Computer Science Paper 2

IF…THEN…ELSE…ENDIF (8.1b)

Adds a second branch that runs when the IF condition is FALSE, so exactly one of the two branches runs. ELSE has no condition of its own and lines up with its IF.

Understanding IF…THEN…ELSE…ENDIF (8.1b) in IGCSE Computer Science Paper 2

What it does: IF, ELSE and ENDIF start in the same column, which shows the two branches belong to one selection. Score is 30, so Score >= 50 is FALSE. The THEN branch is skipped and only Fail is output. ELSE has no condition of its own. The condition belongs to the IF. There are two branches but one result. Either the THEN branch or the ELSE branch runs, never both. ELSE lines up with IF (and ENDIF), so the structure is easy to read. Only the statements inside each branch are indented. The condition goes after IF. The ELSE branch holds the action for when the condition is FALSE.

Common mistakes: The IF line is missing THEN. It should be IF mark >= 50 THEN so the true branch can start. The condition is the wrong way round. High scores would output Fail and low scores Pass. It should be IF score < 40 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 369–378) and word search (Modules 358–378).

Take this worksheet further — free with Cloodit

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

Learning
Duo
In IF…THEN…ELSE…ENDIF, when does the ELSE branch run?
When the IF condition is FALSEWhen the IF condition is TRUE
Matches
IF Mark >= 50 THEN OUTPUT "Pass" ELSE Mark < 50 THEN OUTPUT "Fail" ENDIF
↓
ELSE was given its own condition (Mark < 50 THEN). ELSE has no condition; it just runs when the IF condition is FALSE.
Applying
Meanings
Term
ELSE
Meaning
Adds a second branch that runs when the IF condition is FALSE, so exactly one of the two branches runs. ELSE has no condition of its own and lines up with its IF.
Practice
INPUT mark
Testing
Gaps
OUTPUT "Fail"
Check Answer
Spots
1INPUT mark
2IF mark >= 50

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

The 'Cosmic Dragon' badge — Orbit Master, 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. In IF…THEN…ELSE…ENDIF, when does the ELSE branch run?
A. When the IF condition is FALSE ✓
B. When the IF condition is TRUE
ELSE is the second branch. It only runs when the condition after IF is FALSE.
2. Which line is written correctly in Cambridge pseudocode?
A. ELSE Mark >= 50
B. ELSE ✓
ELSE has no condition of its own. The condition belongs to the IF.
3. Mark is 72. IF Mark >= 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail" ENDIF. What is output?
A. Pass ✓
B. Pass and Fail
The condition is TRUE, so only the THEN branch runs. The ELSE branch is skipped.
4. Mark is 38. IF Mark >= 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail" ENDIF. What is output?
A. Fail ✓
B. Nothing is output
The condition is FALSE, so the ELSE branch runs and outputs Fail.
5. How many branches run each time an IF…ELSE…ENDIF is executed?
A. Both, one after the other
B. Exactly one ✓
There are two branches but one result. Either the THEN branch or the ELSE branch runs, never both.

Match the Pairs

IF Mark >= 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail" ENDIF → Two branches: Pass is output when Mark >= 50 is TRUE, otherwise Fail is output. Exactly one branch runs.
ELSE OUTPUT "Fail" → The ELSE branch, which runs only when the IF condition is FALSE and has no condition of its own.
ELSE lines up with its IF, and ENDIF closes the whole structure → IF Age >= 16 THEN OUTPUT "Allowed" ELSE OUTPUT "Too young" ENDIF
One result only: if the condition is FALSE, only the ELSE branch runs → Score <- 30 IF Score >= 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail" ENDIF
IF Mark >= 50 THEN OUTPUT "Pass" ELSE Mark < 50 THEN OUTPUT "Fail" ENDIF → ELSE was given its own condition (Mark < 50 THEN). ELSE has no condition; it just runs when the IF condition is FALSE.
IF Mark >= 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail" → ENDIF is missing, so the IF...ELSE structure is never closed.

Key Term

ELSE
Adds a second branch that runs when the IF condition is FALSE, so exactly one of the two branches runs. ELSE has no condition of its own and lines up with its IF.

Fill in the Blanks

1. IF Mark >= 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail" ENDIF
Hint: Type the keyword that starts the second branch, which runs when the IF condition is FALSE.
2. IF Mark >= 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail" ENDIF
Hint: Type the keyword that closes the whole selection, after both branches.
3. IF Score >= 40 THEN OUTPUT "Pass" ELSE OUTPUT "Fail" ENDIF
Hint: Type the keyword that comes straight after the IF condition.
4. IF Mark < 50 THEN OUTPUT "Fail" ELSE OUTPUT "Pass" ENDIF
Hint: Type the command that displays a message in the second branch.
5. IF Age >= 18 THEN OUTPUT "Adult" ELSE OUTPUT "Minor" ENDIF
Hint: Type the keyword that begins the selection, which the second-branch keyword lines up with.

Spot the Error

Question 1
A INPUT mark
B IF mark >= 50
C OUTPUT "Pass"
D ELSE
E OUTPUT "Fail"
F ENDIF
Line B — The IF line is missing THEN. It should be IF mark >= 50 THEN so the true branch can start.
Question 2
A IF score > 40 THEN
B OUTPUT "Fail"
C ELSE
D OUTPUT "Pass"
E ENDIF
Line A — The condition is the wrong way round. High scores would output Fail and low scores Pass. It should be IF score < 40 THEN.
Question 3
A IF mark >= 50 THEN
B OUTPUT "Pass"
C ELSE mark < 50
D OUTPUT "Fail"
E ENDIF
Line C — ELSE has no condition of its own. It runs automatically when the IF condition is FALSE, so the line should be just ELSE.
Question 4
A INPUT age
B IF age >= 16 THEN
C ELSE:
D OUTPUT "Too young"
E ENDIF
Line C — Cambridge pseudocode does not use a colon after ELSE. The keyword stands alone on its own line, lined up with its IF, so it should be just ELSE.
Question 5
A IF mark >= 50 THEN
B result <- "Pass"
C ELSE
D result = "Fail"
E ENDIF
Line D — Assignment in Cambridge pseudocode uses the <- arrow, not =. It should be result <- "Fail".

Student with a class code? Join your class →