← IGCSE Computer Science Paper 2

Combining validation checks

Joins several validation checks into one condition, so the input must pass every check. Examples: presence and length together, or range and type together.

Understanding Combining validation checks in IGCSE Computer Science Paper 2

What it does: Each check has its own IF with its own message, so the user is told exactly which check failed. Joining a range check and a whole-number check with AND means the mark is only valid if every check passes. Separate messages help the user fix the exact problem. Every check still has to be run. AND joins the two conditions, so the code is only accepted if it is not empty and has exactly 6 characters. AND means both conditions must be true, so a value outside either limit is rejected. The condition with AND must be followed by THEN before the statements that run when the checks pass.

Common mistakes: The presence and length checks must both pass, so they are joined with AND. With OR, a name that is too long would still be accepted as long as it is not empty. It should be IF Name <> "" AND Len <= 10 THEN. The upper limit of the range check uses the wrong operator. Age >= 9 only accepts 9 or more, so the range 5 to 9 is not checked. It should be Age <= 9.

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
A password must be at least 8 characters AND not empty. Which condition combines both checks so the input must pass every one?
LENGTH(Password) >= 8 AND Password <> ""LENGTH(Password) >= 8 OR Password <> ""
Matches
IF Age >= 11 OR Age <= 16 THEN
↓
OR is used instead of AND, so almost every number passes the range check, because any number is either at least 11 or at most 16.
Applying
Meanings
Term
AND
Meaning
Joins several validation checks into one condition, so the input must pass every check. Examples: presence and length together, or range and type together.
Practice
REPEAT
Testing
Gaps
IF Name <> "" LENGTH(Name) <= 20 THEN
Check Answer
Spots
2Len ← LENGTH(Name)
3IF Name <> "" OR Len <= 10 THEN

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

The 'Kraken' badge — Deep Sea 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. A password must be at least 8 characters AND not empty. Which condition combines both checks so the input must pass every one?
A. LENGTH(Password) >= 8 AND Password <> "" ✓
B. LENGTH(Password) >= 8 OR Password <> ""
AND means both checks must pass. OR would accept the input when only one check passes, so it does not combine checks properly.
2. When two validation checks are joined with AND, when is the input accepted?
A. When it passes at least one check
B. Only when it passes both checks ✓
AND is true only if every condition is true, so the value must pass every check.
3. Which condition checks that Age is a whole number between 11 and 16?
A. Age >= 11 AND Age <= 16 ✓
B. Age >= 11 OR Age <= 16
With OR, almost every number passes (for example 5 or 100), so the range check would be useless. Use AND for the two ends of a range.
4. A username must be present and between 4 and 12 characters long. Which is a presence check plus a length check?
A. Username <> "" AND LENGTH(Username) >= 4 AND LENGTH(Username) <= 12 ✓
B. Username <> "" OR LENGTH(Username) >= 4 OR LENGTH(Username) <= 12
Joining the checks with AND means the username must be present and have a valid length. OR would let an input through that fails some checks.
5. A student types 150 into a field that accepts marks from 0 to 100. The condition is: Mark >= 0 AND Mark <= 100. What happens?
A. The condition is TRUE, because 150 is at least 0
B. The condition is FALSE, so the input is rejected ✓
Mark >= 0 is true but Mark <= 100 is false. With AND, one false check makes the whole condition false.

Match the Pairs

LENGTH(Code) = 6 AND Code <> "" → Combines a length check and a presence check, so the input must pass both
Age >= 11 AND Age <= 16 → Combines two range limits so the value must be at or above 11 and at or below 16
Show a separate error message for each check by testing the checks one at a time → IF Name = "" THEN OUTPUT "Enter a name" ELSE IF LENGTH(Name) > 10 THEN OUTPUT "Too long" ENDIF ENDIF
All checks must be passed, so the valid condition joins them with AND → IF Mark >= 0 AND Mark <= 100 AND Mark = INT(Mark) THEN
IF Age >= 11 OR Age <= 16 THEN → OR is used instead of AND, so almost every number passes the range check, because any number is either at least 11 or at most 16.
IF Code <> "" AND LENGTH(Code) = 6 OUTPUT "OK" → The THEN keyword is missing after the combined condition, so the IF statement is not written correctly.

Key Term

AND
Joins several validation checks into one condition, so the input must pass every check. Examples: presence and length together, or range and type together.

Fill in the Blanks

1. IF Name <> "" AND LENGTH(Name) <= 20 THEN
Hint: Type the logical operator that makes both the presence check and the length check pass.
2. IF IS_NUM(Age) AND Age >= 12 THEN
Hint: Type the function name that checks the value is a number, so the type check and range check are combined.
3. IF LENGTH(Code) <> 5 THEN OUTPUT "Code must be 5 characters" ENDIF
Hint: Type the relational operator meaning not equal, so the length check fails and its own error message shows.
4. REPEAT INPUT Age UNTIL Age >= 12 AND Age <= 18
Hint: Type the keyword that ends this loop once the combined condition is true.
5. WHILE Age < 12 OR Age > 18 DO INPUT Age ENDWHILE
Hint: Type the logical operator that repeats the loop when either of the two range checks fails.

Spot the Error

Question 1
A INPUT Name
B Len ← LENGTH(Name)
C IF Name <> "" OR Len <= 10 THEN
D OUTPUT "Valid"
E ENDIF
Line C — The presence and length checks must both pass, so they are joined with AND. With OR, a name that is too long would still be accepted as long as it is not empty. It should be IF Name <> "" AND Len <= 10 THEN.
Question 2
A INPUT Age
B IF Age >= 5 AND Age >= 9 THEN
C OUTPUT "Accepted"
D ENDIF
Line B — The upper limit of the range check uses the wrong operator. Age >= 9 only accepts 9 or more, so the range 5 to 9 is not checked. It should be Age <= 9.
Question 3
A IF Num >= 1 AND <= 10 THEN
B OUTPUT "In range"
C ELSE
D OUTPUT "Out of range"
E ENDIF
Line A — Each condition joined by AND must be complete and name the variable being checked. The second condition is missing Num. It should be IF Num >= 1 AND Num <= 10 THEN.
Question 4
A INPUT Qty
B Ok ← IS_NUM(Qty) OR Qty > 0
C IF Ok = FALSE THEN
D OUTPUT "Invalid"
E ENDIF
Line B — The type check and the range check must both pass, so they are joined with AND. OR would accept any value that passes just one of the checks. It should be Ok ← IS_NUM(Qty) AND Qty > 0.
Question 5
A IF Pin = "" THEN
B OUTPUT "PIN must be 4 long"
C ENDIF
D IF LENGTH(Pin) <> 4 THEN
E OUTPUT "PIN must be 4 long"
F ENDIF
Line B — Each check needs its own error message. The presence check should tell the user to enter a PIN, not give the length message. Line 2 should be OUTPUT "Enter a PIN".

Student with a class code? Join your class →