← IGCSE Computer Science Paper 2

Using a BOOLEAN function in a condition

A function that RETURNS a BOOLEAN can be called straight in an IF or WHILE condition. The call gives TRUE or FALSE, so no comparison is needed.

Understanding Using a BOOLEAN function in a condition in IGCSE Computer Science Paper 2

What it does: Age >= 18 is TRUE or FALSE, so returning it directly gives the BOOLEAN result of IsAdult. A function call can be used in a loop condition. NOT placed in front of the call reverses TRUE and FALSE. CALL is only for procedures. A function is called inside an expression, so write the name and brackets without CALL. The call is already a BOOLEAN value, so adding = TRUE is redundant and bad style.

Common mistakes: An IF statement must end its condition with THEN. The line should be IF IsEven(Number) THEN. The function needs its argument in brackets. Without (Age) it has no value to test. It should be IF IsAdult(Age) THEN.

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 409–418) and word search (Modules 399–418).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which IF statement correctly uses a BOOLEAN function IsEven to test a number?
IF IsEven THEN NumberIF IsEven(Number) THEN
Matches
IF IsEven(Number) = TRUE THEN
↓
Comparing the BOOLEAN function call with = TRUE is not needed. The call already gives TRUE or FALSE, so it should be IF IsEven(Number) THEN.
Applying
Meanings
Term
IF IsEven(Number) THEN
Meaning
A function that RETURNS a BOOLEAN can be called straight in an IF or WHILE condition. The call gives TRUE or FALSE, so no comparison is needed.
Practice
FUNCTION IsAdult(Age : INTEGER) RETURNS BOOLEAN
Testing
Gaps
IF (Number) THEN
Check Answer
Spots
1INPUT Number
2IF IsEven(Number)

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

The 'Hippopotamus' badge — Savannah Titan, 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 IF statement correctly uses a BOOLEAN function IsEven to test a number?
A. IF IsEven THEN Number
B. IF IsEven(Number) THEN ✓
The function call goes straight into the condition, with its argument in brackets. The call gives TRUE or FALSE.
2. What does the call IsEven(Number) give when it is used in an IF condition?
A. TRUE or FALSE ✓
B. The text "even" or "odd"
A function that RETURNS BOOLEAN gives back TRUE or FALSE, and that is exactly what an IF condition needs.
3. Which function header is correct for a function that checks whether someone is an adult?
A. FUNCTION IsAdult(Age : INTEGER) RETURNS BOOLEAN ✓
B. FUNCTION IsAdult(Age : INTEGER) RETURNS INTEGER
A yes/no check must RETURNS BOOLEAN, because the result is TRUE or FALSE.
4. Inside IsAdult, which line correctly returns TRUE when Age is 18 or more?
A. RETURN Age = 18 THEN TRUE
B. RETURN Age >= 18 ✓
RETURN with a comparison works because the comparison itself gives TRUE or FALSE. No IF is needed.
5. Which condition is a tidier way to test the result of IsAdult(Age)?
A. IF IsAdult(Age) THEN ✓
B. IF IsAdult(Age) = TRUE THEN
The call already gives TRUE or FALSE, so comparing it with TRUE is not needed. Both work, but the first is cleaner.

Match the Pairs

IF IsEven(Number) THEN → Calls the BOOLEAN function IsEven straight in the IF condition. The call gives TRUE or FALSE, so the THEN part runs only when it is TRUE.
WHILE NOT IsPrime(Number) DO → The loop keeps repeating while the BOOLEAN function IsPrime returns FALSE for Number, because NOT turns FALSE into TRUE.
A function that RETURNS a BOOLEAN can use a comparison as its return value, because a comparison gives TRUE or FALSE. → RETURN Age >= 18
A BOOLEAN function can be called straight in an IF condition without comparing it to TRUE. → IF IsAdult(Age) THEN
IF IsEven(Number) = TRUE THEN → Comparing the BOOLEAN function call with = TRUE is not needed. The call already gives TRUE or FALSE, so it should be IF IsEven(Number) THEN.
IF IsAdult THEN → The function call is missing its brackets and argument. It should be IF IsAdult(Age) THEN so the function receives a value.

Key Term

IF IsEven(Number) THEN
A function that RETURNS a BOOLEAN can be called straight in an IF or WHILE condition. The call gives TRUE or FALSE, so no comparison is needed.

Fill in the Blanks

1. IF IsEven(Number) THEN OUTPUT "Even" ENDIF
Hint: Type the name of the BOOLEAN function that is called directly as the condition.
2. FUNCTION IsAdult(A : INTEGER) RETURNS BOOLEAN RETURN A >= 18 ENDFUNCTION
Hint: Type the return data type that lets this function be used as a condition.
3. FUNCTION IsBig(N : INTEGER) RETURNS BOOLEAN RETURN N > 100 ENDFUNCTION
Hint: Type the comparison operator that makes the returned value TRUE when N is greater than 100.
4. WHILE NOT IsValid(Pin) DO INPUT Pin ENDWHILE
Hint: Type the keyword that reverses a BOOLEAN so the loop repeats while the function gives FALSE.
5. IF IsAdult(Age) THEN OUTPUT "Welcome" ENDIF
Hint: Type the keyword that follows the function call at the end of an IF condition.

Spot the Error

Question 1
A INPUT Number
B IF IsEven(Number)
C OUTPUT "Even"
D ENDIF
Line B — An IF statement must end its condition with THEN. The line should be IF IsEven(Number) THEN.
Question 2
A IF IsAdult THEN
B OUTPUT "Entry allowed"
C ENDIF
Line A — The function needs its argument in brackets. Without (Age) it has no value to test. It should be IF IsAdult(Age) THEN.
Question 3
A FUNCTION Full RETURNS BOOLEAN
B RETURNS Count >= 10
C ENDFUNCTION
Line B — The keyword inside a function is RETURN, not RETURNS. RETURNS is only used in the function header. The line should be RETURN Count >= 10.
Question 4
A OUTPUT "Enter an even number"
B INPUT Number
C WHILE IsEven(Number) DO
D INPUT Number
E ENDWHILE
Line C — The loop must keep asking while the number is NOT even. Without NOT it repeats for even numbers and stops on an odd one. It should be WHILE NOT IsEven(Number) DO.
Question 5
A IF IsPass(Mark) = "TRUE" THEN
B OUTPUT "Well done"
C ELSE
D OUTPUT "Try again"
E ENDIF
Line A — IsPass already gives the BOOLEAN value TRUE or FALSE. Comparing it with the string "TRUE" is wrong. It should be IF IsPass(Mark) THEN.

Student with a class code? Join your class →