Range checking in code
A range check: tests that a number lies between a minimum and a maximum (inclusive here). Values outside the limits, such as 0 or 121, are rejected as invalid.
Understanding Range checking in code in VCE Software Development U3O1
What it does: Using <= at both ends means 1 and 100 are valid. Using < would reject them. Dates can be compared like numbers, so a range check works with a start and end date. A range check compares the value against a lower and an upper limit. 1 <= age <= 120 accepts every age from 1 to 120, including both limits. No number is both below 1 and above 120, so 'and' would never be true. 'or' correctly catches values outside either limit. Constants hold the limits in one place, so the range can be changed without hunting through the code.
Common mistakes: The second operator points the wrong way. 'age >= 120' only accepts ages of 120 or more, so most valid ages fail. The upper limit must be 'age <= 120'. No number is both below the minimum and above the maximum, so 'and' never triggers and invalid values slip through. Use 'or' to reject a value outside either limit.
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 114–124) and word search (Modules 114–141).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
1 <= age <= 120Fill in the Blanks
Spot the Error
Student with a class code? Join your class →