← IGCSE Computer Science Paper 2

Choosing between IF and CASE

Use CASE OF when one variable is matched against fixed values, like a menu choice. Use IF when you test conditions with <, > or AND/OR, like age or score tests.

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

What it does: Each CASE clause becomes an IF Choice = value test, with the next test placed inside ELSE. This works but is longer and harder to read than CASE. One variable matched against fixed values like menu options is what CASE is designed for. A test using a relational operator such as >= suits IF. CASE matches values or ranges, not comparison conditions. CASE looks at a single variable. Conditions that combine different variables with AND/OR need IF.

Common mistakes: A menu choice is a good fit for CASE, but the keyword OF is missing. The line should be CASE OF Choice. OTHERWISE belongs in a CASE statement. An IF statement uses ELSE for the alternative, so the line should be ELSE OUTPUT "Pass".

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
A program reads a menu choice (1, 2, 3 or 4) and runs a different action for each. Which structure suits this best?
CASE Choice OFIF Choice > 0 AND Choice < 5
Matches
CASE OF Score >= 50: OUTPUT "Pass" OTHERWISE OUTPUT "Fail" ENDCASE
↓
CASE was used for a score test with a comparison operator (>=). CASE clauses match fixed values or ranges, so use IF Score >= 50 THEN ... ELSE ... ENDIF.
Applying
Meanings
Term
CASE OF
Meaning
Use CASE OF when one variable is matched against fixed values, like a menu choice. Use IF when you test conditions with <, > or AND/OR, like age or score tests.
Practice
INPUT Choice
Testing
Gaps
choice
Check Answer
Spots
2INPUT Choice
3CASE Choice

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

The 'Manta Ray' badge — Graceful 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. A program reads a menu choice (1, 2, 3 or 4) and runs a different action for each. Which structure suits this best?
A. IF Choice > 0 AND Choice < 5
B. CASE Choice OF ✓
One variable matched against fixed values like menu options is what CASE is designed for.
2. A program prints 'Adult' if Age >= 18. Which structure suits this test best?
A. IF Age >= 18 THEN ✓
B. CASE Age >= 18 OF
A test using a relational operator such as >= suits IF. CASE matches values or ranges, not comparison conditions.
3. Which statement about CASE is correct?
A. It compares one variable with several fixed values. ✓
B. It tests several different variables joined with AND and OR.
CASE looks at a single variable. Conditions that combine different variables with AND/OR need IF.
4. A program must check: Score >= 50 AND Attendance >= 90. Which structure should you use?
A. CASE
B. IF ✓
This condition uses two variables and AND, so it needs IF. CASE cannot test two variables at once.
5. A nested IF checks Choice = 1, then Choice = 2, then Choice = 3 inside ELSE. Which is easier to read?
A. Rewriting it as CASE Choice OF ✓
B. Keeping the long nested IF
The same variable is compared with fixed values each time, so CASE is shorter and clearer than IF nested inside ELSE.

Match the Pairs

CASE OF Choice 1: OUTPUT "Start" 2: OUTPUT "Quit" ENDCASE → A menu choice: one variable (Choice) is matched against fixed values, so CASE is the neat choice.
IF Age >= 13 AND Age <= 19 THEN OUTPUT "Teenager" ENDIF → An age test using relational and logical operators, so IF is the right choice, not CASE.
A CASE statement can be rewritten as nested IF by testing the same variable against each fixed value in turn. → IF Choice = 1 THEN OUTPUT "Start" ELSE IF Choice = 2 THEN OUTPUT "Quit" ENDIF ENDIF
Nested IF testing one variable for fixed values is easier to read when rewritten as a CASE statement. → CASE OF Day 1: OUTPUT "Mon" 2: OUTPUT "Tue" OTHERWISE OUTPUT "Other" ENDCASE
CASE OF Score >= 50: OUTPUT "Pass" OTHERWISE OUTPUT "Fail" ENDCASE → CASE was used for a score test with a comparison operator (>=). CASE clauses match fixed values or ranges, so use IF Score >= 50 THEN ... ELSE ... ENDIF.
IF Choice = 1 THEN OUTPUT "Start" ELSE IF Choice = 2 THEN OUTPUT "Quit" ELSE IF Choice = 3 THEN OUTPUT "Help" ENDIF ENDIF ENDIF → Deeply nested IF is used for a menu where one variable is matched against fixed values. This is hard to read and should be a CASE OF Choice statement instead.

Key Term

CASE OF
Use CASE OF when one variable is matched against fixed values, like a menu choice. Use IF when you test conditions with <, > or AND/OR, like age or score tests.

Fill in the Blanks

1. CASE OF choice 1: OUTPUT "Play" ENDCASE
Hint: Type the two-word keyword that starts a selection matching one variable against fixed values, such as a menu choice.
2. IF age >= 18 THEN OUTPUT "Adult" ENDIF
Hint: Type the relational operator meaning 'greater than or equal to'. Age tests like this suit IF, not CASE.
3. IF score >= 50 AND score < 70 THEN OUTPUT "Merit" ENDIF
Hint: Type the logical operator that needs both conditions to be true. This shows IF testing a score range.
4. IF choice = 1 THEN OUTPUT "Play" ELSE OUTPUT "Quit" ENDIF
Hint: Type the keyword that handles every other value when a CASE with OTHERWISE is rewritten as an IF.
5. CASE OF mark 1 TO 4: OUTPUT "Low" ENDCASE
Hint: Type the keyword that joins the start and end values of a range in a CASE clause.

Spot the Error

Question 1
A OUTPUT "1 Play 2 Quit"
B INPUT Choice
C CASE Choice
D 1 : OUTPUT "Playing"
E 2 : OUTPUT "Bye"
F ENDCASE
Line C — A menu choice is a good fit for CASE, but the keyword OF is missing. The line should be CASE OF Choice.
Question 2
A INPUT Score
B IF Score >= 70
C THEN OUTPUT "Distinction"
D OTHERWISE OUTPUT "Pass"
E ENDIF
Line D — OTHERWISE belongs in a CASE statement. An IF statement uses ELSE for the alternative, so the line should be ELSE OUTPUT "Pass".
Question 3
A INPUT Mark
B CASE OF Mark
C 0 TO 49 : OUTPUT "Fail"
D Mark >= 50 : OUTPUT "Pass"
E ENDCASE
Line D — A CASE clause holds fixed values or ranges, not a relational test like >=. Write 50 TO 100 : OUTPUT "Pass", or use an IF statement for >= tests.
Question 4
A INPUT Age
B IF Age < 13 AND Age > 19
C THEN OUTPUT "Not a teen"
D ENDIF
Line B — No age can be below 13 and above 19 at the same time, so AND makes the condition always false. Use OR: IF Age < 13 OR Age > 19.
Question 5
A OUTPUT Option
B CASE OF Option
C "A" : OUTPUT "Add"
D "Q" : OUTPUT "Quit"
E ENDCASE
Line A — The program must read the user's menu choice before the CASE statement tests it. The line should be INPUT Option, not OUTPUT.

Student with a class code? Join your class →