← IGCSE Computer Science Paper 2

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

Runs the statements between THEN and ENDIF only when the condition is TRUE. If the condition is FALSE, they are skipped. This form has no ELSE part.

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

What it does: The condition and THEN are on the first line, and the indented OUTPUT line is the statement that runs only when the condition is TRUE. If Score is 100 or less, the assignment is skipped and Score stays the same. There is no ELSE part to run instead. If the condition is FALSE, the statements between THEN and ENDIF are skipped and the program carries on after ENDIF. Every IF must be closed with the single keyword ENDIF. This form has no ELSE clause, so nothing extra happens when the condition is FALSE.

Common mistakes: Cambridge pseudocode uses OUTPUT to display a message, not PRINT. The line should be OUTPUT "Adult". The keyword that closes an IF block is the single word ENDIF, not END IF. The line should be ENDIF.

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
Which statement describes IF ... THEN ... ENDIF with no ELSE?
The statements run only when the condition is TRUEThe statements always run, whatever the condition is
Matches
IF Temp > 30 OUTPUT "Hot" ENDIF
↓
THEN is missing after the condition. It should be IF Temp > 30 THEN.
Applying
Meanings
Term
IF condition THEN ... ENDIF
Meaning
Runs the statements between THEN and ENDIF only when the condition is TRUE. If the condition is FALSE, they are skipped. This form has no ELSE part.
Practice
INPUT Score
Testing
Gaps
Age >= 18 THEN
Check Answer
Spots
2IF Age >= 18 THEN
3 PRINT "Adult"

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

The 'Armadillo' badge — Shield Bearer, 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 statement describes IF ... THEN ... ENDIF with no ELSE?
A. The statements run only when the condition is TRUE ✓
B. The statements always run, whatever the condition is
If the condition is FALSE, the statements between THEN and ENDIF are skipped and the program carries on after ENDIF.
2. Which is the correct way to close an IF block in Cambridge pseudocode?
A. ENDIF ✓
B. END IF THEN
Every IF must be closed with the single keyword ENDIF.
3. Which layout is correct? A: IF Score > 50 THEN OUTPUT "Pass" ENDIF B: IF Score > 50 THEN (newline) OUTPUT "Pass" (newline) ENDIF
A. A
B. B ✓
Cambridge pseudocode puts THEN at the end of the IF line and the statements on their own indented lines before ENDIF.
4. Score is 40. What happens with this code? IF Score >= 50 THEN OUTPUT "Pass" ENDIF
A. Nothing is output ✓
B. Fail is output
40 >= 50 is FALSE, so OUTPUT is skipped. There is no ELSE part to run instead.
5. Age is 16. What happens with this code? IF Age >= 16 THEN OUTPUT "Can apply" ENDIF
A. Nothing is output
B. Can apply is output ✓
16 >= 16 is TRUE, so the statement between THEN and ENDIF runs.

Match the Pairs

IF Mark >= 50 THEN OUTPUT "Pass" ENDIF → Outputs Pass only when Mark is 50 or more; otherwise nothing is output.
ENDIF → Closes the IF block, marking where the statements that depend on the condition end.
THEN goes on the same line as the condition and the statements to run go on the following indented lines. → IF Age >= 18 THEN OUTPUT "Adult" ENDIF
An IF with no ELSE does nothing when the condition is FALSE and the program carries on after ENDIF. → IF Score > 100 THEN Score <- 100 ENDIF
IF Temp > 30 OUTPUT "Hot" ENDIF → THEN is missing after the condition. It should be IF Temp > 30 THEN.
IF Lives = 0 THEN OUTPUT "Game over" → ENDIF is missing, so the IF block is never closed. Add ENDIF on the last line.

Key Term

IF condition THEN ... ENDIF
Runs the statements between THEN and ENDIF only when the condition is TRUE. If the condition is FALSE, they are skipped. This form has no ELSE part.

Fill in the Blanks

1. IF Age >= 18 THEN OUTPUT "Adult" ENDIF
Hint: Type the keyword that starts a selection block and introduces the condition.
2. IF Score > 50 THEN OUTPUT "Pass" ENDIF
Hint: Type the keyword that comes after the condition and begins the statements to run.
3. IF Temp < 10 THEN OUTPUT "Cold" ENDIF
Hint: Type the keyword that closes the block. There is no ELSE part.
4. IF Age >= 18 THEN OUTPUT "Can vote" ENDIF
Hint: Type the relational operator meaning greater than or equal to.
5. IF Lives = 0 THEN OUTPUT "Game over" ENDIF
Hint: Type the command that displays a message, which only runs when the condition is TRUE.

Spot the Error

Question 1
A INPUT Age
B IF Age >= 18 THEN
C PRINT "Adult"
D ENDIF
Line C — Cambridge pseudocode uses OUTPUT to display a message, not PRINT. The line should be OUTPUT "Adult".
Question 2
A INPUT Score
B IF Score > 50 THEN
C OUTPUT "Pass"
D END IF
Line D — The keyword that closes an IF block is the single word ENDIF, not END IF. The line should be ENDIF.
Question 3
A INPUT Mark
B Count ← 0
C IF Mark > 40
D Count ← Count + 1
E ENDIF
Line C — The IF line is missing THEN. The condition must be followed by THEN, so it should be IF Mark > 40 THEN.
Question 4
A INPUT Temp
B Ice ← FALSE
C IF Temp ← 0 THEN
D Ice ← TRUE
E ENDIF
Line C — A condition compares values, so it needs the relational operator =. The arrow ← is for assignment. The line should be IF Temp = 0 THEN.
Question 5
A IF Lives == 0 THEN
B OUTPUT "Game over"
C ENDIF
Line A — Cambridge pseudocode tests equality with a single =, not ==. The line should be IF Lives = 0 THEN.

Student with a class code? Join your class →