← IGCSE Computer Science Paper 2

Range check

A range check tests that a value lies between the lowest and highest allowed values. The limits themselves are accepted. AND joins both limits.

Understanding Range check in IGCSE Computer Science Paper 2

What it does: Dates can be range checked by testing their parts. Using >= and <= means the limits 1 and 12 are accepted. A value is in range only when it is at least the lowest value AND at most the highest value. AND means both limits must be met. With OR, every number passes because it is always at least 0 or at most 120, so the check would never reject anything. The limits themselves are valid. <= and >= include the limit value, so 0 and 100 both pass. A range check tests the size of the value, not just that it is a number. 150 is greater than 120, so it fails.

Common mistakes: A range check needs AND so the value must meet both limits. With OR, every number passes, even -5 or 500. It should be IF Age >= 0 AND Age <= 120. The THEN branch runs when the mark is inside the range, so it should output "Accepted". Here, valid marks would be rejected.

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 47–57) and word search (Modules 47–70).

Take this worksheet further — free with Cloodit

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

Learning
Duo
A range check on Age allows values from 0 to 120. Which condition accepts a valid age?
IF Age >= 0 OR Age <= 120IF Age >= 0 AND Age <= 120
Matches
IF Age >= 0 OR Age <= 120 THEN
↓
OR is used to join the limits, so every number passes, because any number is either at least 0 or at most 120. It should be AND.
Applying
Meanings
Term
IF Age >= 0 AND Age <= 120
Meaning
A range check tests that a value lies between the lowest and highest allowed values. The limits themselves are accepted. AND joins both limits.
Practice
INPUT Age
Testing
Gaps
IF Age >= 0 Age <= 120 THEN
Check Answer
Spots
1IF Age >= 0 OR Age <= 120
2 THEN

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

The 'Desert Jerboa' badge — High Jumper, 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 range check on Age allows values from 0 to 120. Which condition accepts a valid age?
A. IF Age >= 0 AND Age <= 120 ✓
B. IF Age >= 0 OR Age <= 120
AND means both limits must be met. With OR, every number passes because it is always at least 0 or at most 120, so the check would never reject anything.
2. What does a range check test?
A. The value lies between a lowest and a highest allowed value ✓
B. The value has been typed in twice with the same result
A range check compares a value with its lower and upper limits. Typing data twice is a double entry check, which is verification.
3. A mark must be between 0 and 100 inclusive. Is a mark of 100 accepted by IF Mark >= 0 AND Mark <= 100?
A. No, 100 is rejected because it is on the limit
B. Yes, 100 is accepted because <= includes the limit ✓
The limits themselves are valid. <= and >= include the limit value, so 0 and 100 both pass.
4. Which condition is TRUE when a mark is outside the range 0 to 100?
A. Mark < 0 OR Mark > 100 ✓
B. Mark < 0 AND Mark > 100
A value outside the range is too low OR too high. No number can be below 0 and above 100 at the same time, so AND would never be TRUE.
5. A range check allows 1 to 31 for the day of a month. Which condition wrongly rejects the valid value 31?
A. IF Day >= 1 AND Day <= 31
B. IF Day >= 1 AND Day < 31 ✓
Day < 31 leaves out 31, which is a valid limit value. Day <= 31 includes it.

Match the Pairs

IF Mark >= 0 AND Mark <= 100 THEN → Range check: accepts a Mark from 0 to 100, including 0 and 100 themselves
IF Age < 0 OR Age > 120 THEN → Tests whether Age is outside the allowed range, so the value is rejected
A range check on a date: the month number must be between 1 and 12, and 1 and 12 are valid → IF Month >= 1 AND Month <= 12 THEN
Both limits must be true for a number to pass, so the two tests are joined with AND → IF Score >= 1 AND Score <= 10 THEN
IF Age >= 0 OR Age <= 120 THEN → OR is used to join the limits, so every number passes, because any number is either at least 0 or at most 120. It should be AND.
IF Mark > 0 AND Mark < 100 THEN → The limits 0 and 100 are wrongly rejected because > and < are used. It should be >= and <= so the limits are accepted.

Key Term

IF Age >= 0 AND Age <= 120
A range check tests that a value lies between the lowest and highest allowed values. The limits themselves are accepted. AND joins both limits.

Fill in the Blanks

1. IF Age >= 0 AND Age <= 120 THEN OUTPUT "Age accepted" ENDIF
Hint: Type the logical operator that makes both limits have to be true at the same time.
2. IF Age >= 0 AND Age <= 120 THEN OUTPUT "Age accepted" ENDIF
Hint: Type the relational operator that accepts the highest allowed value itself, as well as smaller ones.
3. IF Age < 0 OR Age > 120 THEN OUTPUT "Invalid age" ENDIF
Hint: Type the logical operator that is true when a value breaks either limit and is outside the range.
4. IF Score >= 0 AND Score <= 100 THEN OUTPUT "Valid score" ENDIF
Hint: Type the relational operator that accepts the lowest allowed value itself, as well as larger ones.
5. IF Month >= 1 AND Month <= 12 THEN OUTPUT "Valid month" ENDIF
Hint: Type the name of the variable whose value is being range checked against the upper limit.

Spot the Error

Question 1
A IF Age >= 0 OR Age <= 120
B THEN
C OUTPUT "Valid"
D ENDIF
Line A — A range check needs AND so the value must meet both limits. With OR, every number passes, even -5 or 500. It should be IF Age >= 0 AND Age <= 120.
Question 2
A INPUT Mark
B IF Mark >= 0 AND Mark <= 100
C THEN OUTPUT "Rejected"
D ELSE OUTPUT "Rejected"
E ENDIF
Line C — The THEN branch runs when the mark is inside the range, so it should output "Accepted". Here, valid marks would be rejected.
Question 3
A INPUT Temp
B IF Temp < -10 OR Temp > 40
C THEN OUTPUT "Outside range"
D ELSE OUTPUT "Outside range"
E ENDIF
Line D — The condition tests for being outside the range, so ELSE means the value is inside it. It should output "In range", not "Outside range".
Question 4
A INPUT Rating
B IF Rating > 1 AND Rating <= 5
C THEN OUTPUT "Accepted"
D ENDIF
Line B — Values on the limits must be accepted. Using > 1 rejects a rating of 1, which is the lowest allowed value. It should be Rating >= 1.
Question 5
A OUTPUT "Enter mark 0-100"
B INPUT Mark
C WHILE Mark < 0 AND Mark > 100
D INPUT Mark
E ENDWHILE
Line C — A number cannot be below 0 and above 100 at the same time, so the loop would never run. To catch values outside the range, use OR: WHILE Mark < 0 OR Mark > 100.

Student with a class code? Join your class →