← IGCSE Computer Science Paper 2

Pseudocode IF ... THEN ... ELSE ... ENDIF

Runs the indented lines after THEN if the condition is true, otherwise runs the ELSE lines. ENDIF closes the construct and sits at the same indent as IF. ELSE is optional.

Understanding Pseudocode IF ... THEN ... ELSE ... ENDIF in IGCSE Computer Science Paper 2

What it does: There is no ELSE, so the OUTPUT line only runs when age < 18 is true. ENDIF lines up with IF to close the construct. Cambridge pseudocode uses <> (or ≠) for 'not equal to'. =! is not a valid operator. A condition compares values using = . The ← arrow is for assignment, so it cannot be used to test a value. ELSE gives the alternative path. It is optional and sits at the same indent as IF and ENDIF.

Common mistakes: The IF line is missing THEN. The condition must be followed by THEN, so it should be IF score >= 50 THEN. The comparison operator is the wrong way round. Minor should be shown when age is less than 18, so the line should be IF age < 18 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 123–134) and word search (Modules 123–145).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which IF statement is written correctly in Cambridge pseudocode?
IF score >= 50 THEN OUTPUT "Pass" ENDIFIF score >= 50 THEN OUTPUT "Pass" END
Matches
IF score >= 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail"
↓
The ENDIF is missing, so the IF construct is never closed. Add ENDIF at the same indent as IF after the ELSE lines.
Applying
Meanings
Term
IF THEN ELSE ENDIF
Meaning
Runs the indented lines after THEN if the condition is true, otherwise runs the ELSE lines. ENDIF closes the construct and sits at the same indent as IF. ELSE is optional.
Practice
IF mark >= 50 THEN
Testing
Gaps
IF Age >= 18
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 'Moose' badge — Tundra Champion, 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 IF statement is written correctly in Cambridge pseudocode?
A. IF score >= 50 THEN OUTPUT "Pass" ENDIF ✓
B. IF score >= 50 THEN OUTPUT "Pass" END
Every IF construct must be closed with ENDIF, not END. ELSE is optional, but ENDIF is always needed.
2. Where should ENDIF be placed?
A. Indented in line with the statements after THEN
B. At the same indent as the IF it closes ✓
IF, ELSE and ENDIF all line up at the same indent. Only the statements inside the branches are indented.
3. What happens when the condition in an IF ... THEN ... ELSE ... ENDIF is false?
A. The indented lines after THEN are run
B. The indented lines after ELSE are run ✓
The THEN lines only run when the condition is true. If it is false, the ELSE lines run instead.
4. What happens when an IF with no ELSE has a false condition?
A. The program skips to the line after ENDIF ✓
B. The program stops with an error
Without an ELSE, nothing extra happens when the condition is false. The program carries on after ENDIF.
5. Which condition correctly checks that age is not equal to 18?
A. IF age <> 18 THEN ✓
B. IF age =! 18 THEN
Cambridge pseudocode uses <> (or ≠) for 'not equal to'. =! is not a valid operator.

Match the Pairs

IF score >= 50 THEN → Starts a selection: the indented lines below run only when score is 50 or more
ELSE → Introduces the lines that run when the IF condition is false
A one-way IF with no ELSE: nothing happens if the condition is false, and ENDIF closes it at the same indent as IF → IF age < 18 THEN OUTPUT "Under 18" ENDIF
A two-way IF with ELSE: one set of lines runs if the condition is true, a different set runs if it is false → IF temp > 30 THEN OUTPUT "Hot" ELSE OUTPUT "Not hot" ENDIF
IF score >= 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail" → The ENDIF is missing, so the IF construct is never closed. Add ENDIF at the same indent as IF after the ELSE lines.
IF mark = 100 THEN OUTPUT "Full marks" ENDIF → ENDIF is indented as if it were inside the IF. It must line up with IF at the same indent.

Key Term

IF THEN ELSE ENDIF
Runs the indented lines after THEN if the condition is true, otherwise runs the ELSE lines. ENDIF closes the construct and sits at the same indent as IF. ELSE is optional.

Fill in the Blanks

1. IF Age >= 18 THEN OUTPUT "Adult" ENDIF
Hint: Type the keyword that follows the condition and starts the block that runs when it is true.
2. IF Score >= 50 THEN OUTPUT "Pass" ENDIF
Hint: Type the comparison operator meaning greater than or equal to.
3. IF Temp < 10 THEN OUTPUT "Cold" ENDIF
Hint: Type the keyword that closes the construct, at the same indent as IF.
4. ELSE OUTPUT "Fail" ENDIF
Hint: Type the keyword that starts the lines run when the condition is false.
5. IF Pin <> 1234 THEN OUTPUT "Wrong PIN" ENDIF
Hint: Type the comparison operator meaning not equal to.

Spot the Error

Question 1
A IF score >= 50
B OUTPUT "Pass"
C ELSE
D OUTPUT "Fail"
E ENDIF
Line A — The IF line is missing THEN. The condition must be followed by THEN, so it should be IF score >= 50 THEN.
Question 2
A INPUT age
B IF age > 18 THEN
C OUTPUT "Minor"
D ELSE
E OUTPUT "Adult"
F ENDIF
Line B — The comparison operator is the wrong way round. Minor should be shown when age is less than 18, so the line should be IF age < 18 THEN.
Question 3
A INPUT guess
B IF guess = 7 THEN
C OUTPUT Correct
D ELSE
E OUTPUT "Wrong"
F ENDIF
Line C — The text to display is missing its quote marks. Without them Correct looks like a variable. It should be OUTPUT "Correct".
Question 4
A INPUT mark
B IF mark => 40 THEN
C OUTPUT "Pass"
D ENDIF
Line B — The comparison operator is written the wrong way round. 'Greater than or equal to' is >=, not =>.
Question 5
A IF lives ← 0 THEN
B OUTPUT "Game over"
C ENDIF
Line A — ← is for assignment, not for comparing. A condition that tests equality uses =, so it should be IF lives = 0 THEN.

Student with a class code? Join your class →