← IGCSE Computer Science Paper 2

IF…THEN…ENDIF (8.1b)

Runs the indented statements only when the condition is TRUE. If it is FALSE they are skipped. ENDIF closes the selection and lines up with IF.

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

What it does: If Age is below 18 the OUTPUT "Adult" line is skipped, but OUTPUT "Done" still runs because it comes after ENDIF. Both indented statements belong to the IF, so they either both run (TRUE) or are both skipped (FALSE). 62 is greater than 50, so the condition is TRUE and the statements in the THEN branch run. Cambridge pseudocode closes an IF statement with the single keyword ENDIF. Every IF needs its own ENDIF, written at the same indentation as IF, to show where the selection stops. The condition must be followed by THEN on the same line: IF Score >= 50 THEN.

Common mistakes: The text to output is missing its closing quotation mark. It should be ' OUTPUT "Pass"'. An IF selection is closed with ENDIF, not ENDWHILE. ENDWHILE closes a WHILE loop.

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
Score is 62. What happens to OUTPUT "Pass" in: IF Score >= 50 THEN / OUTPUT "Pass" / ENDIF?
It is skipped, because 62 >= 50 is FALSEIt runs, because 62 >= 50 is TRUE
Matches
IF Score >= 50 THEN OUTPUT "Pass"
↓
The ENDIF is missing, so the IF statement is never closed
Applying
Meanings
Term
IF condition THEN ... ENDIF
Meaning
Runs the indented statements only when the condition is TRUE. If it is FALSE they are skipped. ENDIF closes the selection and lines up with IF.
Practice
IF Score >= 50
Testing
Gaps
Score >= 50 THEN
Check Answer
Spots
2IF Score >= 50 THEN
3 OUTPUT "Pass

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

The 'Firefly' badge — Night Coder, 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. Score is 62. What happens to OUTPUT "Pass" in: IF Score >= 50 THEN / OUTPUT "Pass" / ENDIF?
A. It runs, because 62 >= 50 is TRUE ✓
B. It is skipped, because 62 >= 50 is FALSE
62 is greater than 50, so the condition is TRUE and the statements in the THEN branch run.
2. Score is 35. What happens to OUTPUT "Pass" in: IF Score >= 50 THEN / OUTPUT "Pass" / ENDIF?
A. It is skipped and the program carries on after ENDIF ✓
B. The program stops with an error
When the condition is FALSE, the indented statements are skipped and the program continues after ENDIF. There is no error.
3. Which is the correct way to close a selection in Cambridge pseudocode?
A. END IF THEN
B. ENDIF ✓
Cambridge pseudocode closes an IF statement with the single keyword ENDIF.
4. Which layout is correct?
A. IF Score >= 50 THEN (newline) indented OUTPUT "Pass" (newline) ENDIF lined up with IF ✓
B. IF Score >= 50 THEN (newline) indented OUTPUT "Pass" (newline) ENDIF indented like the OUTPUT
ENDIF lines up with IF. Only the statements inside the THEN branch are indented.
5. Which IF line is written correctly?
A. IF Score >= 50
B. IF Score >= 50 THEN ✓
The condition must be followed by THEN, which starts the branch of statements that run when it is TRUE.

Match the Pairs

IF Score >= 50 THEN → Starts a selection that runs the indented lines below only when Score is 50 or more
ENDIF → Closes the IF statement and lines up directly under the IF it belongs to
When the condition is FALSE, the statements in the THEN branch are skipped and the program carries on after ENDIF → IF Age >= 18 THEN OUTPUT "Adult" ENDIF OUTPUT "Done"
The THEN branch can hold more than one indented statement, and all of them run only when the condition is TRUE → IF Score >= 50 THEN Passed <- Passed + 1 OUTPUT "Pass" ENDIF
IF Score >= 50 THEN OUTPUT "Pass" → The ENDIF is missing, so the IF statement is never closed
IF Score >= 50 OUTPUT "Pass" ENDIF → THEN is missing after the condition

Key Term

IF condition THEN ... ENDIF
Runs the indented statements only when the condition is TRUE. If it is FALSE they are skipped. ENDIF closes the selection and lines up with IF.

Fill in the Blanks

1. IF Score >= 50 THEN OUTPUT "Pass" ENDIF
Hint: Type the keyword that starts the selection statement.
2. IF Score >= 50 THEN OUTPUT "Pass" ENDIF
Hint: Type the keyword that comes after the condition and begins the branch run when it is TRUE.
3. IF Score >= 50 THEN OUTPUT "Pass" ENDIF
Hint: Type the relational operator that means greater than or equal to.
4. IF Score >= 50 THEN OUTPUT "Pass" ENDIF
Hint: Type the keyword that closes the selection, lined up with the IF.
5. IF Score >= 50 THEN OUTPUT "Well done" ENDIF
Hint: Type the statement name that displays a message when the condition is TRUE.

Spot the Error

Question 1
A INPUT Score
B IF Score >= 50 THEN
C OUTPUT "Pass
D ENDIF
Line C — The text to output is missing its closing quotation mark. It should be ' OUTPUT "Pass"'.
Question 2
A IF Mark > 90 THEN
B OUTPUT "Top mark"
C ENDWHILE
Line C — An IF selection is closed with ENDIF, not ENDWHILE. ENDWHILE closes a WHILE loop.
Question 3
A INPUT Age
B IF Age >= 16
C OUTPUT "Can apply"
D ENDIF
Line B — The IF line is missing the keyword THEN after the condition. It should be 'IF Age >= 16 THEN'.
Question 4
A IF Score >= 50 THEN
B OUTPUT "Pass"
C Passes = Passes + 1
D ENDIF
Line C — Assignment uses the arrow <-. A single = is a comparison in Cambridge pseudocode. It should be 'Passes <- Passes + 1'.
Question 5
A INPUT Temp
B IF Temp <- 30 THEN
C OUTPUT "Exactly 30"
D ENDIF
Line B — A condition compares values, so it needs the relational operator =. The arrow <- is for assignment. It should be 'IF Temp = 30 THEN'.

Student with a class code? Join your class →