← IGCSE Computer Science Paper 2

Presence check

A validation check that tests something has been entered, so the input is not empty. For example, Name <> "" or LENGTH(Name) > 0 makes sure a required field is not left blank.

Understanding Presence check in IGCSE Computer Science Paper 2

What it does: The loop keeps asking while the required Name field is empty, so the user must enter something before the program continues. The condition is true only when at least one character has been entered, which is how a presence check accepts input. Required fields on a form use a presence check. A range check tests that a number lies between a lowest and highest value. A string with a length greater than 0 is not empty, so this tests that something has been entered.

Common mistakes: The presence check is the wrong way round. Name = "" is true when nothing was entered, so 'Accepted' would show for an empty name. It should be IF Name <> "" THEN. The loop must repeat while the name is empty, so the user is asked again. Name <> "" repeats when a name has been entered. It should be WHILE Name = "" DO.

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 47–57) 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
What does a presence check test?
That the data entered is actually true and correctThat something has been entered, so the input is not empty
Matches
IF Name = "" THEN OUTPUT "Accepted"
↓
The condition is the wrong way round. It accepts an empty Name, so it does not check that something was entered. It should be Name <> "".
Applying
Meanings
Term
Presence check
Meaning
A validation check that tests something has been entered, so the input is not empty. For example, Name <> "" or LENGTH(Name) > 0 makes sure a required field is not left blank.
Practice
OUTPUT "Enter your name"
Testing
Gaps
IF Name "" THEN
Check Answer
Spots
1INPUT Name
2IF Name = "" THEN

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

The 'Jellyfish' badge — Flow Controller, 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. What does a presence check test?
A. That something has been entered, so the input is not empty ✓
B. That the data entered is actually true and correct
A presence check only tests that the field is not left empty. It cannot tell whether the data is sensible or true.
2. Which condition is a presence check on Name?
A. Name <> "" ✓
B. Name = ""
Name <> "" is TRUE when Name is not empty, so the data is present. Name = "" is TRUE when the field is blank.
3. Which condition also works as a presence check on Name?
A. LENGTH(Name) = 0
B. LENGTH(Name) > 0 ✓
A name with a length greater than 0 contains at least one character, so something has been entered. A length of 0 means it is empty.
4. A form has a required field for an email address. Which check makes sure it is not left blank?
A. Range check
B. Presence check ✓
Required fields on a form use a presence check. A range check tests that a number lies between a lowest and highest value.
5. A student types "Zxq" into a required Name field and the presence check passes. Is this correct?
A. Yes, a presence check only checks the field is not empty ✓
B. No, a presence check would reject a name that looks wrong
The presence check passes because something was entered. It does not check whether the name is real or spelled correctly.

Match the Pairs

Name <> "" → A presence check that is true only when Name is not empty, so something has been entered
LENGTH(Name) > 0 → A presence check that is true only when Name has at least one character
A presence check makes sure a required field on a form is not left blank → WHILE Name = "" DO INPUT Name ENDWHILE
A presence check passes when the input is not empty → IF LENGTH(Email) > 0 THEN
IF Name = "" THEN OUTPUT "Accepted" → The condition is the wrong way round. It accepts an empty Name, so it does not check that something was entered. It should be Name <> "".
IF LENGTH(Name) < 0 THEN → No string can have a length less than 0, so this test is never true. A presence check needs LENGTH(Name) > 0.

Key Term

Presence check
A validation check that tests something has been entered, so the input is not empty. For example, Name <> "" or LENGTH(Name) > 0 makes sure a required field is not left blank.

Fill in the Blanks

1. IF Name <> "" THEN OUTPUT "Thank you" ENDIF
Hint: Type the relational operator that means not equal to, so the presence check passes when something was entered.
2. IF LENGTH(Name) > 0 THEN OUTPUT "Thank you" ENDIF
Hint: Type the function name that returns how many characters are in a string.
3. IF LENGTH(Name) > 0 THEN OUTPUT "Thank you" ENDIF
Hint: Type the relational operator that checks the length is more than zero, so the field is not empty.
4. REPEAT INPUT Name UNTIL Name <> ""
Hint: Type the keyword that ends a loop which re-asks for input until the condition is true.
5. IF Name = "" THEN OUTPUT "Name is required" ENDIF
Hint: Type the command that shows an error message to the user when a required field is left blank.

Spot the Error

Question 1
A INPUT Name
B IF Name = "" THEN
C OUTPUT "Accepted"
D ENDIF
Line B — The presence check is the wrong way round. Name = "" is true when nothing was entered, so 'Accepted' would show for an empty name. It should be IF Name <> "" THEN.
Question 2
A OUTPUT "Enter your name"
B INPUT Name
C WHILE Name <> "" DO
D OUTPUT "Name required"
E INPUT Name
F ENDWHILE
Line C — The loop must repeat while the name is empty, so the user is asked again. Name <> "" repeats when a name has been entered. It should be WHILE Name = "" DO.
Question 3
A INPUT Name
B IF LENGTH(Name) < 0 THEN
C OUTPUT "Name saved"
D ELSE
E OUTPUT "Name is required"
F ENDIF
Line B — A length can never be less than 0, so this condition is never true and every name is rejected. A presence check needs LENGTH(Name) > 0.
Question 4
A REPEAT
B OUTPUT "Enter a username"
C INPUT UserName
D UNTIL UserName = ""
E OUTPUT "Welcome"
Line D — A REPEAT loop stops when the UNTIL condition is true. UserName = "" would stop the loop only when nothing is entered. It should be UNTIL UserName <> "".
Question 5
A INPUT Surname
B Valid ← TRUE
C IF Surname = "" THEN
D Valid ← TRUE
E ENDIF
F OUTPUT Valid
Line D — When the surname is empty the presence check has failed, so Valid must be set to FALSE. Setting it to TRUE means an empty field would be accepted.

Student with a class code? Join your class →