ProceduralOCR J277
DashboardCoursePracticeReviewProgressGlossary
Saved on this deviceContinue learning

Procedural · OCR J277 programming practice

Progress stays in this browser unless you export it.

Course/Robust programs/Range validation with loops
J277 · 2.3.1

Unit 10 · Lesson 2

Range validation with loops

Lesson progress0 / 7

Build the idea

Start with the concept and its key vocabulary.

Key idea

Implement an inclusive range check inside a condition-controlled loop.

A range check accepts only values between lower and upper limits. Validation does not prove that data is true; it checks that it is reasonable for the program. A while loop can repeat while the value is outside the range. The input that can end the loop must be taken again inside the loop.

Validation

Checking that input is reasonable and follows required rules before processing it.

Range check

A check that a value lies between permitted lower and upper limits.

Inclusive

Including the boundary values themselves.

Re-prompt

Ask for input again after an invalid value.

Keep these in mind

  • An inclusive valid range uses lower <= value AND value <= upper.
  • The invalid condition can use value < lower OR value > upper.
  • Read the first value before the loop and re-read it inside the loop.
  • Use <= and >=, not =< or mathematical symbols.
  • Validation checks user input; generated values do not need this check.

Learning objective

Implement an inclusive range check inside a condition-controlled loop.

Exam tip

Compare the variable in both parts: height >= 40 AND height <= 180. A missing second variable reference loses the condition's meaning.

Common mistake

If the new input is outside the loop, an invalid first value never changes and the loop cannot finish.

PreviousNext