📘 Paper 2 · Topic 8: Programming
8.1b Selection: IF and CASE OF
Cambridge IGCSE Computer Science 0478 · ~14 min read · ⭐ Pro

Selection — Making Decisions

Selection is a programming construct that allows a program to execute different code depending on whether a condition is true or false. This is how programs make decisions.

IF...THEN...ELSE...ENDIF

The simplest form of selection. If the condition is TRUE, the first block runs. If FALSE, the ELSE block runs (optional).

Basic IF structure

IF condition THEN
    // code to run if condition is TRUE
ENDIF

IF...ELSE structure

IF score >= 50 THEN
    OUTPUT "Pass"
ELSE
    OUTPUT "Fail"
ENDIF

Nested IF (IF inside IF)

IF score >= 70 THEN
    OUTPUT "Grade A"
ELSE
    IF score >= 50 THEN
        OUTPUT "Grade B"
    ELSE
        OUTPUT "Fail"
    ENDIF
ENDIF

Using ELSE IF (more efficient for multiple conditions)

IF score >= 70 THEN
    OUTPUT "Grade A"
ELSE IF score >= 60 THEN
    OUTPUT "Grade B"
ELSE IF score >= 50 THEN
    OUTPUT "Grade C"
ELSE
    OUTPUT "Fail"
ENDIF

CASE OF...ENDCASE

CASE OF is used when you want to select from several discrete options based on the value of a single variable. It's cleaner than a long chain of IF...ELSE IF when you have many options.

CASE OF day
    1: OUTPUT "Monday"
    2: OUTPUT "Tuesday"
    3: OUTPUT "Wednesday"
    4: OUTPUT "Thursday"
    5: OUTPUT "Friday"
    6: OUTPUT "Saturday"
    7: OUTPUT "Sunday"
    OTHERWISE: OUTPUT "Invalid day"
ENDCASE

CASE OF with strings

CASE OF choice
    "A": OUTPUT "Option A selected"
    "B": OUTPUT "Option B selected"
    "C": OUTPUT "Exit"
    OTHERWISE: OUTPUT "Invalid choice"
ENDCASE

When to use IF vs CASE OF

Use IF when...Use CASE OF when...
Testing a range of values (e.g., score >= 50)Testing for specific exact values
Complex boolean conditions (AND/OR)Selecting from a menu of options
Two alternatives onlyMany discrete alternatives
Exam tip: Always match ENDIF to every IF, and ENDCASE to every CASE OF. In exams, Cambridge questions often ask you to write pseudocode for grade boundaries — remember to use ELSE IF rather than separate IFs so only ONE branch runs.
⚠️ Common Mistakes
  • Forgetting ENDIF — every IF must have a matching ENDIF
  • Using separate IFs instead of ELSE IF — with separate IFs, multiple branches could run; with ELSE IF, only one runs
  • Forgetting OTHERWISE in CASE OF — if no case matches and there is no OTHERWISE, nothing runs
  • Using CASE OF for range conditions (e.g., score >= 50) — CASE OF is only for exact matches
Video coming soon
Click slide or press arrow keys to navigate
✍️

Worksheet — Selection

4 questions · 10 marks

Q1Write pseudocode using IF...ELSE to check if a number is even or odd. (Hint: use MOD) [3]
✅ Mark scheme
INPUT number [1]; IF number MOD 2 = 0 THEN OUTPUT "Even" [1]; ELSE OUTPUT "Odd" ENDIF [1]
Q2Write pseudocode using CASE OF to output a season based on a month number (1-12). Include at least Spring (3-5), Summer (6-8) and OTHERWISE. [4]
✅ Mark scheme
CASE OF month [1]; 3,4,5: OUTPUT "Spring" [1]; 6,7,8: OUTPUT "Summer" [1]; OTHERWISE: OUTPUT "Autumn or Winter" (or appropriate seasons for other months) [1]; ENDCASE
Q3Explain why ELSE IF is better than separate IF statements when testing grade boundaries. [2]
✅ Mark scheme
With separate IF statements, multiple branches could execute if more than one condition is TRUE [1]; with ELSE IF, as soon as one condition is TRUE the others are skipped — guaranteeing only one branch runs [1]
Q4State one situation where CASE OF should NOT be used instead of IF. [1]
✅ Mark scheme
Any one: when testing a range of values (e.g., score >= 50) [1]; when using complex conditions with AND/OR [1]; CASE OF only matches exact values, not ranges [1]
Quiz — Selection
Q 1 of 7
Score
/ 7
Click to reveal
TermDefinition
🎯

Mini Test — Selection

10 minutes · mixed marks

← 8.1a Programming Concepts Topic 8: Programming Next: 8.1c Iteration →
🔒
Pro Content
Upgrade to access all lessons.
£7.99/month
or £59/year
Subscribe now →