← IGCSE Computer Science Paper 2

Choosing between CASE and IF

Use CASE OF to test one variable against single values, like a menu choice. Use IF for ranges, like grade boundaries, or when conditions combine several variables.

Understanding Choosing between CASE and IF in IGCSE Computer Science Paper 2

What it does: Each case is one single value of Choice with a single statement, which is what CASE is designed for. The condition uses two variables (Age and HasTicket) and a range, so it must be an IF statement. A condition that combines two variables needs IF. CASE only tests one variable against single values.

Common mistakes: Each CASE branch tests one single value, like a menu choice. A range such as 1 TO 2 needs an IF statement. It should be 1 : OUTPUT "Play". OTHERWISE belongs only in a CASE statement. An IF statement uses ELSE for the other branch.

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 166–175) and word search (Modules 166–187).

Take this worksheet further — free with Cloodit

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

Learning
Duo
A program reads a menu choice of 1, 2 or 3 and runs a different action for each. Which structure fits best?
CASE Choice OFThree separate IF statements that each test ranges
Matches
CASE OF Mark 70 TO 100 : Grade ← "A" ENDCASE
↓
Grade boundaries are ranges, so CASE is the wrong choice. Use IF Mark >= 70 THEN instead.
Applying
Meanings
Term
CASE OF
Meaning
Use CASE OF to test one variable against single values, like a menu choice. Use IF for ranges, like grade boundaries, or when conditions combine several variables.
Practice
OUTPUT "1 Play 2 Help 3 Quit"
Testing
Gaps
Choice OF
Check Answer
Spots
2CASE OF Choice
3 1 TO 2 : OUTPUT "Play"

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

The 'Badger' badge — Determined Digger, 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. A program reads a menu choice of 1, 2 or 3 and runs a different action for each. Which structure fits best?
A. CASE Choice OF ✓
B. Three separate IF statements that each test ranges
One variable (Choice) is tested against single values, so CASE OF is the neat choice.
2. A program converts a mark into a grade: A for 80 or more, B for 60 to 79, C for 40 to 59. Which structure fits best?
A. CASE Mark OF
B. IF ... THEN ... ELSE ✓
Grade boundaries are ranges. A CASE value would have to list every single mark, so IF is better.
3. Which condition CANNOT be handled neatly by a CASE statement?
A. 1: OUTPUT "Start game"
B. IF Age >= 13 AND Score > 50 THEN ✓
A condition that combines two variables needs IF. CASE only tests one variable against single values.
4. Which line is a correct case in a CASE statement for a menu?
A. 2: OUTPUT "Load game" ✓
B. 2 TO 4: OUTPUT "Load game"
Each case in these exam-style statements has a single value followed by a colon and one statement.
5. A user types a letter: 'S' to save, 'L' to load, 'Q' to quit. Which should you use?
A. CASE Letter OF ✓
B. IF Letter > 'A' AND Letter < 'Z' THEN
The variable Letter is compared with single values, so CASE OF fits a menu-style choice.

Match the Pairs

CASE OF Choice → Tests one variable, Choice, against several single values such as 1, 2 or 3, like a menu
IF Mark >= 70 THEN → Tests a range of values, so IF is used rather than CASE, as in grade boundaries
A menu where the user picks 1, 2 or 3 is one variable tested against single values, so use CASE → CASE OF Choice 1 : OUTPUT "Play" 2 : OUTPUT "Quit" ENDCASE
A condition that combines two variables cannot be written as a CASE, so use IF → IF Age >= 16 AND HasTicket = TRUE THEN
CASE OF Mark 70 TO 100 : Grade ← "A" ENDCASE → Grade boundaries are ranges, so CASE is the wrong choice. Use IF Mark >= 70 THEN instead.
IF Choice = 1 THEN OUTPUT "Play" ELSE IF Choice = 2 THEN OUTPUT "Quit" ENDIF ENDIF → A menu tests one variable against single values, so CASE OF Choice is clearer than long nested IF statements.

Key Term

CASE OF
Use CASE OF to test one variable against single values, like a menu choice. Use IF for ranges, like grade boundaries, or when conditions combine several variables.

Fill in the Blanks

1. CASE Choice OF 1 : OUTPUT "Play" ENDCASE
Hint: Type the keyword that tests one variable against single values, like a menu choice.
2. CASE Choice OF 2 : OUTPUT "Quit" ENDCASE
Hint: Type the keyword that comes after the variable name on the CASE line.
3. IF Mark >= 70 THEN OUTPUT "Merit" ENDIF
Hint: Type the relational operator that means 'greater than or equal to', used for a grade boundary.
4. IF Age >= 13 AND Score > 50 THEN OUTPUT "Pass" ENDIF
Hint: Type the logical operator that needs both conditions true when two variables are combined.
5. CASE Choice OF 3 : OUTPUT "Help" ENDCASE
Hint: Type the keyword that closes a CASE statement.

Spot the Error

Question 1
A INPUT Choice
B CASE OF Choice
C 1 TO 2 : OUTPUT "Play"
D 2 : OUTPUT "Quit"
E ENDCASE
Line C — Each CASE branch tests one single value, like a menu choice. A range such as 1 TO 2 needs an IF statement. It should be 1 : OUTPUT "Play".
Question 2
A IF Mark >= 70 THEN
B Grade ← "A"
C OTHERWISE
D Grade ← "B"
E ENDIF
Line C — OTHERWISE belongs only in a CASE statement. An IF statement uses ELSE for the other branch.
Question 3
A INPUT Choice
B CASE OF Choice
C 1 : OUTPUT "Play"
D 2 OUTPUT "Quit"
E ENDCASE
Line D — Each CASE value must be followed by a colon before its statement. It should be 2 : OUTPUT "Quit".
Question 4
A INPUT Pct
B IF Pct >= 40 AND < 60 THEN
C OUTPUT "Merit"
D ENDIF
Line B — A range needs IF with a full condition on each side of AND. The variable must be repeated: Pct >= 40 AND Pct < 60.
Question 5
A INPUT Option
B CASE Option OF
C 1 : OUTPUT "Open"
D 2 : OUTPUT "Save"
E ENDCASE
Line B — The CASE header is written CASE OF followed by the variable being tested. It should be CASE OF Option.

Student with a class code? Join your class →