← IGCSE Computer Science Paper 2

IF ... THEN ... ELSE ... ENDIF (7a)

Gives IF a second path. The THEN statements run when the condition is TRUE and the ELSE statements run when it is FALSE. Exactly one path runs, never both.

Understanding IF ... THEN ... ELSE ... ENDIF (7a) in IGCSE Computer Science Paper 2

What it does: If Answer = 4 is TRUE, Correct is set to TRUE and the ELSE line is skipped. If it is FALSE, Correct ← FALSE runs instead. IF, ELSE and ENDIF start at the same position, and the statements under THEN and ELSE are indented two spaces. There is no ENDELSE. The whole IF statement, including its ELSE part, is closed by one ENDIF. ELSE has no condition of its own. It simply covers the case when the IF condition is FALSE.

Common mistakes: The IF line is missing THEN. It should be IF Age >= 18 THEN so the THEN statements can follow the condition. Assignment uses the arrow ←, not =. The line should be Correct ← TRUE. In pseudocode = is used to compare values.

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 37–46) and word search (Modules 27–46).

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 part run?
When the condition is FALSEWhen the condition is TRUE
Matches
IF Age >= 16 THEN OUTPUT "Adult" ELSE OUTPUT "Child"
↓
The ENDIF is missing, so the IF ... THEN ... ELSE statement is never closed.
Applying
Meanings
Term
ELSE
Meaning
Gives IF a second path. The THEN statements run when the condition is TRUE and the ELSE statements run when it is FALSE. Exactly one path runs, never both.
Practice
IF Answer = 4
Testing
Gaps
Check Answer
Spots
1INPUT Age
2IF Age >= 18

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

The 'African Wild Dog' badge — Savannah Streak, 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 part run?
A. When the condition is FALSE ✓
B. When the condition is TRUE
ELSE is the second path. It runs only when the condition is FALSE. The THEN part runs when the condition is TRUE.
2. How many paths run when an IF ... THEN ... ELSE ... ENDIF is executed once?
A. Exactly one path ✓
B. Both paths, one after the other
The condition is either TRUE or FALSE, so exactly one path runs: THEN or ELSE, never both.
3. Which is the correct way to lay out IF with ELSE in Cambridge pseudocode?
A. IF Mark >= 50 THEN Result ← "Pass" ELSE Result ← "Fail" ENDIF
B. IF Mark >= 50 THEN Result ← "Pass" ELSE Result ← "Fail" ENDIF ✓
The statements inside THEN and ELSE are indented two spaces. IF, ELSE and ENDIF line up with each other.
4. Which line must finish an IF ... THEN ... ELSE statement?
A. ENDIF ✓
B. ENDELSE
There is no ENDELSE. The whole IF statement, including its ELSE part, is closed by one ENDIF.
5. Age is 12. What is the value of Correct after this code runs? IF Age >= 13 THEN Correct ← TRUE ELSE Correct ← FALSE ENDIF
A. TRUE
B. FALSE ✓
Age >= 13 is FALSE when Age is 12, so the ELSE path runs and Correct ← FALSE is executed.

Match the Pairs

ELSE → Gives an IF statement a second path that runs when the condition is FALSE
IF Score >= 50 THEN Result ← "Pass" ELSE Result ← "Fail" ENDIF → Exactly one path runs: Pass if Score is 50 or more, otherwise Fail
When the condition is TRUE, the THEN statements run and the ELSE statements are skipped → IF Answer = 4 THEN Correct ← TRUE ELSE Correct ← FALSE ENDIF
In Cambridge pseudocode, THEN and ELSE statements are indented two spaces and ELSE lines up with IF → IF Age >= 16 THEN OUTPUT "Adult" ELSE OUTPUT "Child" ENDIF
IF Age >= 16 THEN OUTPUT "Adult" ELSE OUTPUT "Child" → The ENDIF is missing, so the IF ... THEN ... ELSE statement is never closed.
IF Answer = 4 THEN Correct ← TRUE ELSE Answer <> 4 THEN Correct ← FALSE ENDIF → ELSE has a condition and a THEN added to it, but ELSE never takes a condition.

Key Term

ELSE
Gives IF a second path. The THEN statements run when the condition is TRUE and the ELSE statements run when it is FALSE. Exactly one path runs, never both.

Fill in the Blanks

1. ELSE Correct ← FALSE ENDIF
Hint: Type the keyword that starts the second path, which runs when the condition is FALSE.
2. ELSE Correct ← FALSE ENDIF
Hint: Type the BOOLEAN value that is assigned when the condition is not met.
3. IF Guess = 7 THEN Correct ← TRUE ELSE
Hint: Type the keyword that follows the condition and begins the path that runs when it is TRUE.
4. IF Guess = 7 THEN Correct ← TRUE ELSE
Hint: Type the BOOLEAN value assigned when the condition is met.
5. ELSE Correct ← FALSE ENDIF
Hint: Type the keyword that closes the whole selection statement after both paths.

Spot the Error

Question 1
A INPUT Age
B IF Age >= 18
C OUTPUT "Adult"
D ELSE
E OUTPUT "Child"
F ENDIF
Line B — The IF line is missing THEN. It should be IF Age >= 18 THEN so the THEN statements can follow the condition.
Question 2
A INPUT Answer
B IF Answer = 12 THEN
C Correct = TRUE
D ELSE
E Correct ← FALSE
F ENDIF
Line C — Assignment uses the arrow ←, not =. The line should be Correct ← TRUE. In pseudocode = is used to compare values.
Question 3
A INPUT Password
B IF Password == "cat" THEN
C OUTPUT "Welcome"
D ELSE
E OUTPUT "Denied"
F ENDIF
Line B — Cambridge pseudocode compares with a single =, not ==. The line should be IF Password = "cat" THEN.
Question 4
A INPUT Temp
B IF Temp > 25 THEN
C OUTPUT "Hot"
D ELSE Temp <= 25
E OUTPUT "Cool"
F ENDIF
Line D — ELSE has no condition. It simply runs when the IF condition is FALSE. The line should be just ELSE.
Question 5
A INPUT Number
B IF Number MOD 2 = 0 THEN
C OUTPUT "Odd"
D ELSE
E OUTPUT "Odd"
F ENDIF
Line C — The THEN path runs when the condition is TRUE. When Number MOD 2 = 0 the number is even, so this line should be OUTPUT "Even".

Student with a class code? Join your class →