← IGCSE Computer Science Paper 2

Input validation with REPEAT…UNTIL

Ends a REPEAT loop only when Mark is valid (0 to 100). Input is asked again until it passes this range check, so the program only continues with valid data.

Understanding Input validation with REPEAT…UNTIL in IGCSE Computer Science Paper 2

What it does: The REPEAT loop is a post-condition loop: INPUT runs first and the range check comes after, so the user is always asked once. With OR, one true part is enough: a mark below 0 or above 100 is outside the range, so the error message is shown. Valid means both checks must pass, so AND is needed. With OR, any number satisfies at least one check, so every value would be accepted. A range check only tests that a value falls within allowed limits. It cannot know whether the value is the actual correct mark, but it stops impossible values like 150.

Common mistakes: OR makes the condition true for every number, because any number is either at least 0 or at most 100. The loop would accept invalid marks. A range check needs AND: UNTIL Mark>=0 AND Mark<=100. The loop must ask for a new value each time round, so line 2 should be INPUT Mark. With OUTPUT, no value is ever read and the user cannot correct a bad mark.

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 379–388) and word search (Modules 379–398).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which loop is most suitable for validating a Mark, because the prompt must run at least once?
FOR...NEXTREPEAT...UNTIL
Matches
REPEAT INPUT Mark UNTIL Mark >= 0 OR Mark <= 100
↓
OR makes the condition true for every number, so the loop ends on any input and invalid marks are accepted. It should use AND.
Applying
Meanings
Term
UNTIL Mark >= 0 AND Mark <= 100
Meaning
Ends a REPEAT loop only when Mark is valid (0 to 100). Input is asked again until it passes this range check, so the program only continues with valid data.
Practice
REPEAT
Testing
Gaps
UNTIL Mark >= 0 Mark <= 100
Check Answer
Spots
2 INPUT Mark
3UNTIL Mark>=0 OR Mark<=100

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

The 'Woodland Hedgehog' badge — Import Master, 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 loop is most suitable for validating a Mark, because the prompt must run at least once?
A. REPEAT...UNTIL ✓
B. FOR...NEXT
REPEAT...UNTIL checks the condition after the body, so the INPUT always runs once before the first check. FOR is for a known number of repeats.
2. Which condition correctly accepts only marks from 0 to 100?
A. UNTIL Mark >= 0 OR Mark <= 100
B. UNTIL Mark >= 0 AND Mark <= 100 ✓
Valid means both checks must pass, so AND is needed. With OR, any number satisfies at least one check, so every value would be accepted.
3. When does a REPEAT...UNTIL validation loop stop asking for input?
A. When the UNTIL condition becomes TRUE ✓
B. When the UNTIL condition becomes FALSE
REPEAT...UNTIL repeats while the condition is FALSE and exits once it is TRUE. For validation, TRUE means the data is valid.
4. Where should the error message go in a validation loop?
A. After ENDWHILE, once the loop has finished
B. Inside the loop, shown when the input is invalid ✓
The error message belongs inside the loop so the user sees it each time they enter a bad value. After the loop the data is already valid. Also, REPEAT loops end with UNTIL, not ENDWHILE.
5. A student types 150 for Mark. What happens with UNTIL Mark >= 0 AND Mark <= 100?
A. The condition is FALSE, so the loop repeats and asks again ✓
B. The condition is TRUE, so the loop ends and 150 is accepted
150 fails Mark <= 100, so the AND condition is FALSE. The loop runs again and the INPUT is repeated.

Match the Pairs

UNTIL Mark >= 0 AND Mark <= 100 → Repeats the loop until the mark is in the valid range of 0 to 100 inclusive
OUTPUT "Invalid mark, try again" → Shows an error message inside the loop when the value fails the range check
REPEAT is suitable for validation because the prompt must run at least once before the check → REPEAT INPUT Mark UNTIL Mark >= 0 AND Mark <= 100
An OR condition can be used to detect invalid data, so the error message appears when the mark is out of range → IF Mark < 0 OR Mark > 100 THEN OUTPUT "Invalid mark" ENDIF
REPEAT INPUT Mark UNTIL Mark >= 0 OR Mark <= 100 → OR makes the condition true for every number, so the loop ends on any input and invalid marks are accepted. It should use AND.
REPEAT INPUT Mark UNTIL Mark >= 0 AND Mark <= 100 → The UNTIL line is indented and sits like it is inside the loop body, and the error message is missing. UNTIL should line up with REPEAT, with the OUTPUT message placed before it inside the loop.

Key Term

UNTIL Mark >= 0 AND Mark <= 100
Ends a REPEAT loop only when Mark is valid (0 to 100). Input is asked again until it passes this range check, so the program only continues with valid data.

Fill in the Blanks

1. REPEAT INPUT Mark UNTIL Mark >= 0 AND Mark <= 100
Hint: Type the logical operator that makes both range limits true at once.
2. REPEAT INPUT Mark UNTIL Mark >= 0 AND Mark <= 100
Hint: Type the keyword that ends the loop and holds the range check.
3. REPEAT INPUT Mark UNTIL Mark >= 0 AND Mark <= 100
Hint: Type the keyword that starts a loop whose prompt must run at least once.
4. REPEAT INPUT Mark UNTIL NOT (Mark < 0 OR Mark > 100)
Hint: Type the logical operator that joins the two invalid cases inside the brackets.
5. REPEAT INPUT Mark UNTIL Mark >= 0 AND Mark <= 100
Hint: Type the statement that asks the user for a value again on each repeat.

Spot the Error

Question 1
A REPEAT
B INPUT Mark
C UNTIL Mark>=0 OR Mark<=100
D OUTPUT Mark
Line C — OR makes the condition true for every number, because any number is either at least 0 or at most 100. The loop would accept invalid marks. A range check needs AND: UNTIL Mark>=0 AND Mark<=100.
Question 2
A REPEAT
B OUTPUT Mark
C UNTIL Mark>=0 AND Mark<=100
D OUTPUT Mark
Line B — The loop must ask for a new value each time round, so line 2 should be INPUT Mark. With OUTPUT, no value is ever read and the user cannot correct a bad mark.
Question 3
A WHILE Mark<0 DO
B INPUT Mark
C UNTIL Mark>=0 AND Mark<=100
Line A — A loop that ends with UNTIL must start with REPEAT. WHILE...DO belongs with ENDWHILE. REPEAT also suits validation because the prompt must run at least once.
Question 4
A REPEAT
B INPUT Mark
C IF Mark<0 AND Mark>100 THEN
D OUTPUT "Invalid mark"
E ENDIF
F UNTIL Mark>=0 AND Mark<=100
Line C — No number can be below 0 and above 100 at the same time, so the error message would never show. An invalid mark is below 0 OR above 100: IF Mark<0 OR Mark>100 THEN.
Question 5
A REPEAT
B INPUT Mark
C IF Mark<0 OR Mark>100 THEN
D INPUT "Invalid mark"
E ENDIF
F UNTIL Mark>=0 AND Mark<=100
Line D — The error message must be shown to the user, so it needs OUTPUT, not INPUT. INPUT would try to read a value into a variable. It should be OUTPUT "Invalid mark".

Student with a class code? Join your class →