← IGCSE Computer Science Paper 2

CASE clauses with ranges and several statements

In a CASE clause, value1 TO value2 matches a whole range, such as 1 TO 9. Indented statements under the clause all run. Ranges in one CASE must not overlap.

Understanding CASE clauses with ranges and several statements in IGCSE Computer Science Paper 2

What it does: The range is written as value1 TO value2, followed by a colon and the statement to run. The ranges 0 TO 49 and 50 TO 100 share no values, so every mark matches exactly one clause. A CASE clause lists values or a range using TO. It does not use relational operators like < in the clause. Ranges in one CASE must not overlap. In the wrong pair, 50 would match both clauses. All the indented statements under a matching clause run, one after the other. Range ends are included. 75 is the first value of 75 TO 100 and is outside 50 TO 74.

Common mistakes: A range in a CASE clause is written with TO, not a hyphen. It should be 40 TO 69 : OUTPUT "B". The colon is missing after the range. A clause must be written 1 TO 9 : OUTPUT "Low".

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
Which CASE clause correctly matches every whole number from 1 to 9?
1 - 9 : OUTPUT "Low"1 TO 9 : OUTPUT "Low"
Matches
0 TO 50 : grade <- "F" 50 TO 100 : grade <- "P"
↓
The ranges overlap because 50 is in both 0 TO 50 and 50 TO 100. The first range should end at 49.
Applying
Meanings
Term
1 TO 9 :
Meaning
In a CASE clause, value1 TO value2 matches a whole range, such as 1 TO 9. Indented statements under the clause all run. Ranges in one CASE must not overlap.
Practice
CASE OF Mark
Testing
Gaps
0 49 : OUTPUT "Fail"
Check Answer
Spots
2 70 TO 100 : OUTPUT "A"
3 40 - 69 : OUTPUT "B"

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

The 'Puffin' badge — Definition Diver, 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 CASE clause correctly matches every whole number from 1 to 9?
A. 1 TO 9 : OUTPUT "Low" ✓
B. 1 - 9 : OUTPUT "Low"
A range in a CASE clause is written value1 TO value2, followed by a colon and the statement.
2. Which clause is a valid grade band for marks from 50 up to 69?
A. 50 < Mark < 69 : Grade <- "B"
B. 50 TO 69 : Grade <- "B" ✓
A CASE clause lists values or a range using TO. It does not use relational operators like < in the clause.
3. Which pair of CASE clauses is written correctly for marks 0 to 100?
A. 0 TO 49 : and 50 TO 100 : ✓
B. 0 TO 50 : and 50 TO 100 :
Ranges in one CASE must not overlap. In the wrong pair, 50 would match both clauses.
4. A clause has two indented statements under it. What happens when its range matches?
A. Only the first statement runs
B. Both indented statements run, in order ✓
All the indented statements under a matching clause run, one after the other.
5. The clauses are 0 TO 49, 50 TO 74 and 75 TO 100. Mark is 75. Which clause runs?
A. 75 TO 100 ✓
B. 50 TO 74
Range ends are included. 75 is the first value of 75 TO 100 and is outside 50 TO 74.

Match the Pairs

1 TO 9 : → A CASE clause that matches any value from 1 up to 9, including both 1 and 9
70 TO 100 : grade <- "A" OUTPUT grade → A range clause whose two indented statements both run when the value is between 70 and 100
A range clause for the grade band 50 to 69 that sets the grade to B → 50 TO 69 : grade <- "B"
Ranges in the same CASE must not overlap, so each mark belongs to only one band → 0 TO 49 : 50 TO 100 :
0 TO 50 : grade <- "F" 50 TO 100 : grade <- "P" → The ranges overlap because 50 is in both 0 TO 50 and 50 TO 100. The first range should end at 49.
CASE OF mark 1 - 9 : OUTPUT "Low" ENDCASE → A range must be written with the keyword TO, not a hyphen. It should be 1 TO 9 :

Key Term

1 TO 9 :
In a CASE clause, value1 TO value2 matches a whole range, such as 1 TO 9. Indented statements under the clause all run. Ranges in one CASE must not overlap.

Fill in the Blanks

1. CASE OF Score 0 TO 49 : OUTPUT "Fail" ENDCASE
Hint: Type the keyword that joins the lowest and highest values of a range in a CASE clause.
2. CASE OF Mark 50 TO 69 : OUTPUT "Merit" ENDCASE
Hint: Type the keyword that displays a message when the Mark falls in this range.
3. CASE OF Mark 1 TO 9 : Total <- Total + Mark OUTPUT Total
Hint: Type the variable that was updated by the statement on the line above, which is part of the same clause.
4. 0 TO 49 : Grade <- "F" 50 TO 100 : Grade <- "P" ENDCASE
Hint: Type the number that starts the next grade band, with no overlap and no gap after the previous range ends.
5. CASE OF Mark 1 TO 9 : OUTPUT "Low" ENDCASE
Hint: Type the keyword that closes the whole CASE structure.

Spot the Error

Question 1
A CASE OF Mark
B 70 TO 100 : OUTPUT "A"
C 40 - 69 : OUTPUT "B"
D ENDCASE
Line C — A range in a CASE clause is written with TO, not a hyphen. It should be 40 TO 69 : OUTPUT "B".
Question 2
A CASE OF Score
B 1 TO 9 OUTPUT "Low"
C 10 TO 99 : OUTPUT "High"
D ENDCASE
Line B — The colon is missing after the range. A clause must be written 1 TO 9 : OUTPUT "Low".
Question 3
A CASE OF Mark
B 70 TO 100 :
C OUTPUT "Pass"
D Passes <- Pass + 1
E ENDCASE
Line D — The statement must add 1 to the same variable it assigns to. Pass is a different, undeclared variable. It should be Passes <- Passes + 1.
Question 4
A CASE Mark
B 50 TO 100 : OUTPUT "Pass"
C OTHERWISE : OUTPUT "Fail"
D ENDCASE
Line A — The CASE statement must start with CASE OF followed by the variable. The word OF is missing, so it should be CASE OF Mark.
Question 5
A CASE OF Age
B 0 TO 13 : OUTPUT "Child"
C 13 TO 19 : OUTPUT "Teen"
D ENDCASE
Line B — Ranges in one CASE must not overlap. 0 TO 13 includes 13, which is also in 13 TO 19. It should be 0 TO 12.

Student with a class code? Join your class →