← IGCSE Computer Science Paper 2

Writing a validated input algorithm in pseudocode

DECLARE the variable, OUTPUT a prompt, INPUT the value, OUTPUT an error message if it fails the check, and REPEAT ... UNTIL the value is acceptable.

Understanding Writing a validated input algorithm in pseudocode in IGCSE Computer Science Paper 2

What it does: DECLARE creates the variable with its data type before the INPUT command stores a value in it. Comparing with <> "" checks that something was typed, so the loop repeats until the field is not empty. UNTIL holds the condition for an ACCEPTABLE value. The loop stops when the value is valid. The wrong line describes invalid values. Keywords such as REPEAT and UNTIL are written in capital letters. The lines inside the loop are indented so the structure is clear.

Common mistakes: A DECLARE statement needs a colon between the identifier and the data type. It should be DECLARE Age : INTEGER. Cambridge pseudocode keywords must be written in capital letters. The loop must start with REPEAT, not Repeat.

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 60–70) 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
Which line should come first in a validation algorithm for a variable called Age?
DECLARE Age : INTEGERINPUT Age
Matches
REPEAT INPUT Mark UNTIL Mark < 0 OR Mark > 100
↓
The UNTIL condition tests for invalid values, so the loop stops when the mark is wrong. It should be Mark >= 0 AND Mark <= 100.
Applying
Meanings
Term
validation loop
Meaning
DECLARE the variable, OUTPUT a prompt, INPUT the value, OUTPUT an error message if it fails the check, and REPEAT ... UNTIL the value is acceptable.
Practice
DECLARE Age : INTEGER
Testing
Gaps
Age : INTEGER
Check Answer
Spots
1DECLARE Age INTEGER
2REPEAT

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

The 'Ermine' badge — Tundra Streak, 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 line should come first in a validation algorithm for a variable called Age?
A. INPUT Age
B. DECLARE Age : INTEGER ✓
The variable is declared with its data type before it is used. Only then can you prompt for it and INPUT a value.
2. Which shows the correct order inside a validation loop?
A. OUTPUT "Enter age" then INPUT Age ✓
B. INPUT Age then OUTPUT "Enter age"
The prompt is shown first so the user knows what to type. INPUT then reads the value.
3. A program must accept an age from 1 to 120. Which UNTIL line is correct?
A. UNTIL Age >= 1 AND Age <= 120 ✓
B. UNTIL Age < 1 OR Age > 120
UNTIL holds the condition for an ACCEPTABLE value. The loop stops when the value is valid. The wrong line describes invalid values.
4. Where should the error message be placed in a REPEAT ... UNTIL validation loop?
A. After the UNTIL line, so it always runs once at the end
B. Inside the loop, in an IF that runs when the check fails ✓
The error message must be shown each time a bad value is entered, so it goes inside the loop. After UNTIL the value is already valid.
5. Which UNTIL line gives a correct presence check on Name?
A. UNTIL Name <> "" ✓
B. UNTIL Name = ""
A presence check makes sure something was entered. The loop should stop when Name is NOT empty, so use <> "".

Match the Pairs

REPEAT INPUT Age UNTIL Age >= 0 AND Age <= 120 → Keeps asking for input until the value passes a range check between 0 and 120
UNTIL LENGTH(Password) >= 8 → Loop exit condition that repeats until the password passes a length check of at least 8 characters
A validation algorithm must first declare the variable that will store the input → DECLARE Score : INTEGER
A presence check loop repeats until the input is not empty → REPEAT INPUT Name UNTIL Name <> ""
REPEAT INPUT Mark UNTIL Mark < 0 OR Mark > 100 → The UNTIL condition tests for invalid values, so the loop stops when the mark is wrong. It should be Mark >= 0 AND Mark <= 100.
REPEAT OUTPUT "Enter age" INPUT Age UNTIL Age >= 0 AND Age <= 120 → There is no error message when the value is rejected, and the variable Age is never declared with DECLARE Age : INTEGER before the loop.

Key Term

validation loop
DECLARE the variable, OUTPUT a prompt, INPUT the value, OUTPUT an error message if it fails the check, and REPEAT ... UNTIL the value is acceptable.

Fill in the Blanks

1. DECLARE Age : INTEGER OUTPUT "Enter your age (1-120)" INPUT Age
Hint: Type the keyword that creates a variable before it is used, written in capital letters.
2. DECLARE Age : INTEGER OUTPUT "Enter your age (1-120)" INPUT Age
Hint: Type the command that reads the user's value into the variable, after the prompt has been shown.
3. REPEAT INPUT Age UNTIL Age >= 1 AND Age <= 120
Hint: Type the logical operator that makes a range check require both limits to be satisfied.
4. REPEAT INPUT Password UNTIL LENGTH(Password) >= 8
Hint: Type the function that returns how many characters a string has, used for a length check.
5. IF Name = "" THEN OUTPUT "Please enter a name" ENDIF
Hint: Type the command that displays an error message to the user when a presence check fails.

Spot the Error

Question 1
A DECLARE Age INTEGER
B REPEAT
C OUTPUT "Enter age (1-99)"
D INPUT Age
E UNTIL Age >= 1 AND Age <= 99
Line A — A DECLARE statement needs a colon between the identifier and the data type. It should be DECLARE Age : INTEGER.
Question 2
A DECLARE Name : STRING
B Repeat
C OUTPUT "Enter your name"
D INPUT Name
E UNTIL Name <> ""
Line B — Cambridge pseudocode keywords must be written in capital letters. The loop must start with REPEAT, not Repeat.
Question 3
A DECLARE Pass : STRING
B REPEAT
C OUTPUT "Enter password"
D READ Pass
E UNTIL LENGTH(Pass) >= 8
Line D — READ is not a Cambridge pseudocode command. The value must be read with INPUT, so the line should be INPUT Pass.
Question 4
A DECLARE Mark : INTEGER
B REPEAT
C INPUT "Enter mark (0-10)"
D INPUT Mark
E UNTIL Mark >= 0 AND Mark <= 10
Line C — The prompt for the user must be shown with OUTPUT. INPUT is used to store the value in a variable, so the line should be OUTPUT "Enter mark (0-10)".
Question 5
A DECLARE Qty : INTEGER
B REPEAT
C OUTPUT Enter quantity
D INPUT Qty
E UNTIL Qty >= 1 AND Qty <= 20
Line C — The text of a prompt must be inside double quotes, otherwise it looks like identifiers. The line should be OUTPUT "Enter quantity".

Student with a class code? Join your class →