← IGCSE Computer Science Paper 2

CASE OF ... ENDCASE (7c)

Compares one variable with a list of single values and runs the statement for the first match only. Each case is indented two spaces and the structure ends with ENDCASE.

Understanding CASE OF ... ENDCASE (7c) in IGCSE Computer Science Paper 2

What it does: The case 'W' is indented two spaces under CASE OF. It runs Position ← Position - 10 when Direction is 'W', and ENDCASE closes the structure. A CASE statement starts with CASE OF followed by the identifier. THEN is used in IF statements, not in CASE. CASE tests one identifier against single values such as 'W', 'E' or 'N'. The 'W' case subtracts 10 from Position, so 50 - 10 = 40. CASE OF is followed by the one variable being compared. Each case below it is a value that Direction might hold. Every CASE OF must be closed with ENDCASE, just as IF is closed with ENDIF.

Common mistakes: The OF keyword is missing. A CASE statement must start CASE OF followed by the identifier, so the line should be CASE OF Key. The colon is missing after the case value. Each case needs a value, then a colon, then the statement: 'S' : Pos ← Pos + 10.

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 156–165) and word search (Modules 146–165).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which line correctly starts a CASE statement that tests the variable Direction?
CASE OF DirectionCASE Direction THEN
Matches
CASE OF Direction 'W' : Position ← Position - 10
↓
ENDCASE is missing, so the CASE structure is never closed
Applying
Meanings
Term
CASE OF ... ENDCASE
Meaning
Compares one variable with a list of single values and runs the statement for the first match only. Each case is indented two spaces and the structure ends with ENDCASE.
Practice
CASE OF Key
Testing
Gaps
Direction
Check Answer
Spots
1CASE Key
2 'W' : Pos ← Pos - 10

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

The 'Abyssal Dragon' badge — Deep Sea Legend, 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 line correctly starts a CASE statement that tests the variable Direction?
A. CASE OF Direction ✓
B. CASE Direction THEN
A CASE statement starts with CASE OF followed by the identifier. THEN is used in IF statements, not in CASE.
2. Which keyword correctly ends a CASE statement?
A. ENDIF
B. ENDCASE ✓
Every CASE OF structure must finish with ENDCASE. ENDIF belongs to IF statements.
3. Which case line correctly moves the position left when the value is 'W'?
A. 'W' = Position ← Position - 10
B. 'W' : Position ← Position - 10 ✓
Each case has the value, then a colon, then the statement to run. A = sign is not used to separate the value from the statement.
4. How should the case lines be laid out inside CASE OF ... ENDCASE?
A. Each case indented by two spaces ✓
B. Each case written at the left margin with no indent
Cambridge pseudocode indents each case line by two spaces so the structure is easy to read.
5. Direction is 'W'. Two case lines both start with 'W'. How many of them run?
A. Only the first matching case ✓
B. Every matching case
CASE runs the statement for the first value that matches and then skips the rest.

Match the Pairs

CASE OF Direction → Starts a CASE structure that compares the variable Direction with a list of single values
ENDCASE → Marks the end of the CASE structure
Each case is a single value, a colon and a statement, indented two spaces, and the structure ends with ENDCASE → CASE OF Direction 'W' : Position ← Position - 10 ENDCASE
Only the first matching case runs, so if Direction is 'W' only the 'W' statement is carried out → CASE OF Direction 'W' : Position ← Position - 10 'E' : Position ← Position + 10 ENDCASE
CASE OF Direction 'W' : Position ← Position - 10 → ENDCASE is missing, so the CASE structure is never closed
CASE OF Direction 'W' : Position ← Position - 10 ENDCASE → The 'W' case is not indented by two spaces under CASE OF

Key Term

CASE OF ... ENDCASE
Compares one variable with a list of single values and runs the statement for the first match only. Each case is indented two spaces and the structure ends with ENDCASE.

Fill in the Blanks

1. CASE OF Direction 'W' : Position ← Position - 10 ENDCASE
Hint: Type the two upper case keywords that open a selection on one variable.
2. CASE OF Direction 'W' : Position ← Position - 10 ENDCASE
Hint: Type the single upper case keyword that closes the whole structure.
3. CASE OF Direction 'W' : Position ← Position - 10 ENDCASE
Hint: Type the arithmetic operator that moves the position back when heading West.
4. CASE OF Direction 'W' : Position ← Position - 10 ENDCASE
Hint: Type the punctuation that separates a case value from its statement.
5. CASE OF Direction 'W' : Position ← Position - 10 ENDCASE
Hint: Type the pseudocode assignment symbol that stores the new value in Position.

Spot the Error

Question 1
A CASE Key
B 'W' : Pos ← Pos - 10
C 'S' : Pos ← Pos + 10
D ENDCASE
Line A — The OF keyword is missing. A CASE statement must start CASE OF followed by the identifier, so the line should be CASE OF Key.
Question 2
A CASE OF Key
B 'W' : Pos ← Pos - 10
C 'S' Pos ← Pos + 10
D ENDCASE
Line C — The colon is missing after the case value. Each case needs a value, then a colon, then the statement: 'S' : Pos ← Pos + 10.
Question 3
A CASE OF Move
B 'L' : Pos ← Pos - 1
C 'R' ; Pos ← Pos + 1
D ENDCASE
Line C — A semicolon is used instead of a colon. The case value and its statement must be separated by a colon: 'R' : Pos ← Pos + 1.
Question 4
A CASE OF Key
B 'W' : Pos ← Pos - 10
C 'S' : Pos ← Pos + 10
D ENDIF
Line D — A CASE statement must finish with ENDCASE, not ENDIF. ENDIF is only for IF statements.
Question 5
A CASE OF Key
B 'W' : Pos ← Pos - 10
C 'S' : Pos ← Pos + 10
D ELSE OUTPUT "Invalid"
E ENDCASE
Line D — A CASE statement uses OTHERWISE for the default action, not ELSE. The line should be OTHERWISE OUTPUT "Invalid".

Student with a class code? Join your class →