AQA · GCSE · Computer Science
Course version: 8525 · Version from Sept 2020
Checking if data entered lies within a given range (eg between 1 and 10).
Full specification wording
Robust and secure programming: checking if data entered lies within a given range (eg between 1 and 10).
Range checking confirms that a value falls between a lower and an upper limit before the program uses it.
Checked against the AQA 8525 specification (opens in a new tab) on .
- Point 3 of 14
Study notes
From the checked teaching notes for this specification point.
The idea
Range checking confirms that a value falls between a lower and an upper limit before the program uses it. For the example given, valid data must be at least 1 and at most 10, so the program tests whether the value is greater than or equal to 1 and less than or equal to 10. If the value is outside that range, the program should reject it, display an explanatory message and ask for the input again. The limits themselves are inclusive in this example, so 1 and 10 are both accepted. Range checking is a validation technique: it reduces the chance of the program processing impossible or unintended values, but it cannot guarantee that the data is correct in every respect, because a value inside the range may still be the wrong choice. Learners should be able to state the condition, identify accepted and rejected values, and explain the response to invalid input.
What earns the marks
- A range check tests whether a value lies between a lower limit and an upper limit.
- For the example, the condition accepts values greater than or equal to 1 and less than or equal to 10.
- Values below 1 or above 10 fail the check and should be rejected.
- On failure the program should display a message and re-read the input rather than continue.
- Range checking is validation and reduces, but does not eliminate, the risk of incorrect data.
Common mistakes and how to put them right
Using strict inequalities so that 1 and 10 are rejected.
Put it right: , use greater than or equal to the lower limit and less than or equal to the upper limit for an inclusive range.
Confusing range checking with a type check.
Put it right: , a range check compares magnitude against limits, whereas a type check confirms the kind of data.
Continuing to process the value after it fails the check.
Put it right: , reject, message and re-prompt before use.
Exam tips
- Write the condition with both limits and the correct inclusive operators.
- Give one accepted value and one rejected value to show the boundary behaviour.
- Explain the follow-up action on failure, not just the test itself.
Try the lesson
The start of the Robust and secure programming: checking if data entered lies within a given range (eg between 1 and 10). lesson, made from checked teaching notes for this specification point.
Have a go first
A program accepts a number only if it is between 1 and 10 inclusive. Which condition correctly tests this?
There is more to this lesson
The full lesson goes on to check your understanding and help you earn the marks. Create a free account to carry on, with your progress saved.
A week of Premium from your first lesson · Then the free plan continues · No card, no charge
Test your understanding of Robust and secure programming: checking if data entered lies within a given range (eg between 1 and 10).
Active recall beats re-reading. Take an instant quiz now to test what you’ve learned and lock it into long-term memory.
A week of Premium from your first lesson · Then the free plan continues · No card, no charge