← IGCSE Computer Science Paper 2

Logical operators AND, OR, NOT

Logical operators that combine BOOLEAN conditions: AND needs both true, OR needs at least one true, NOT reverses a condition. Use brackets in complex ones, e.g. Age >= 0 AND Age <= 120.

Understanding Logical operators AND, OR, NOT in IGCSE Computer Science Paper 2

What it does: An answer is invalid if it is below 0 or above 100. OR only needs one of the two conditions to be true. The brackets make the OR happen first. Then the AND checks that the person is also a member. Both parts must be true for a valid age, so AND is needed. With OR, almost any number (e.g. 500 or -5) would pass. OR needs at least one true condition. Needing both true describes AND. Each side of AND must be a complete condition, so Age must be repeated on both sides. NOT reverses the result of the condition in the brackets, so it is true whenever Score is not 50.

Common mistakes: With OR, only one part has to be true, so every number passes (for example -5 is <= 120). A valid age must be >= 0 AND <= 120, so both parts must be true. No number can be below 0 and above 100 at the same time, so AND is never true and bad answers are never caught. It should be OR, because only one part needs to be true.

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 27–36) and word search (Modules 27–46).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which condition correctly checks that Age is between 0 and 120 inclusive?
Age >= 0 OR Age <= 120Age >= 0 AND Age <= 120
Matches
IF Age >= 0 OR Age <= 120 THEN
↓
OR is used where AND is needed. Every number is at least 0 or at most 120, so invalid ages like -5 or 200 still pass. It should be Age >= 0 AND Age <= 120.
Applying
Meanings
Term
AND OR NOT
Meaning
Logical operators that combine BOOLEAN conditions: AND needs both true, OR needs at least one true, NOT reverses a condition. Use brackets in complex ones, e.g. Age >= 0 AND Age <= 120.
Practice
IF (Score < 0 OR Score > 100) AND NOT Retake THEN
Testing
Gaps
IF Age >= 0 Age <= 120 THEN
Check Answer
Spots
1INPUT Age
2IF Age >= 0 OR Age <= 120

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

The 'Stag' badge — Forest Legend, 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 condition correctly checks that Age is between 0 and 120 inclusive?
A. Age >= 0 OR Age <= 120
B. Age >= 0 AND Age <= 120 ✓
Both parts must be true for a valid age, so AND is needed. With OR, almost any number (e.g. 500 or -5) would pass.
2. Which condition is TRUE when Answer is outside the range 0 to 100?
A. Answer < 0 OR Answer > 100 ✓
B. Answer < 0 AND Answer > 100
A number cannot be below 0 and above 100 at the same time, so AND is never true. OR needs only one part to be true.
3. Age is 25. What is the result of Age >= 0 AND Age <= 120?
A. FALSE
B. TRUE ✓
25 >= 0 is TRUE and 25 <= 120 is TRUE. AND needs both parts true, so the result is TRUE.
4. Answer is 150. What is the result of Answer < 0 OR Answer > 100?
A. TRUE ✓
B. FALSE
Answer < 0 is FALSE but Answer > 100 is TRUE. OR needs at least one part true, so the result is TRUE.
5. What does NOT do to a condition?
A. It reverses TRUE to FALSE and FALSE to TRUE ✓
B. It makes both parts of the condition have to be true
NOT reverses a condition. Requiring both parts to be true is the job of AND.

Match the Pairs

Age >= 0 AND Age <= 120 → True only when both conditions are true, so the age is inside the valid range 0 to 120
NOT (Score = 50) → Reverses the condition: true when Score is anything except 50
OR is true when at least one condition is true, so it can catch a value outside a range → Answer < 0 OR Answer > 100
Brackets make clear which conditions are combined first in a complex condition → (Age < 13 OR Age > 19) AND Member = TRUE
IF Age >= 0 OR Age <= 120 THEN → OR is used where AND is needed. Every number is at least 0 or at most 120, so invalid ages like -5 or 200 still pass. It should be Age >= 0 AND Age <= 120.
IF Answer < 0 AND Answer > 100 THEN → AND is used where OR is needed. No number can be below 0 and above 100 at the same time, so the condition is never true. It should be Answer < 0 OR Answer > 100.

Key Term

AND OR NOT
Logical operators that combine BOOLEAN conditions: AND needs both true, OR needs at least one true, NOT reverses a condition. Use brackets in complex ones, e.g. Age >= 0 AND Age <= 120.

Fill in the Blanks

1. IF Age >= 0 AND Age <= 120 THEN OUTPUT "Age accepted" ENDIF
Hint: Type the logical operator that needs both conditions to be true.
2. IF Answer < 0 OR Answer > 100 THEN OUTPUT "Out of range" ENDIF
Hint: Type the logical operator that is true when at least one condition is true.
3. IF NOT (Age >= 18) THEN OUTPUT "Under 18" ENDIF
Hint: Type the logical operator that reverses the result of a condition.
4. WHILE NOT (Answer >= 0 AND Answer <= 100) DO INPUT Answer ENDWHILE
Hint: Type the operator inside the brackets that makes a valid answer pass both range tests.
5. Valid ← (Age >= 0) AND (Age <= 120) OUTPUT Valid
Hint: Type the logical operator that joins the two bracketed conditions so the BOOLEAN is TRUE only if both are met.

Spot the Error

Question 1
A INPUT Age
B IF Age >= 0 OR Age <= 120
C THEN
D OUTPUT "Valid"
E ENDIF
Line B — With OR, only one part has to be true, so every number passes (for example -5 is <= 120). A valid age must be >= 0 AND <= 120, so both parts must be true.
Question 2
A IF Answer < 0 AND Answer > 100
B THEN
C OUTPUT "Out of range"
D ENDIF
Line A — No number can be below 0 and above 100 at the same time, so AND is never true and bad answers are never caught. It should be OR, because only one part needs to be true.
Question 3
A INPUT Age
B INPUT Paid
C IF Age >= 5 OR Paid = TRUE
D THEN
E OUTPUT "Enter"
F ENDIF
Line C — Entry needs BOTH conditions to be true: old enough AND paid. With OR, someone aged 5 or over gets in without paying. It should use AND.
Question 4
A DECLARE Fail : BOOLEAN
B INPUT Mark
C Fail ← FALSE
D IF NOT (Mark < 50)
E THEN Fail ← TRUE
F ENDIF
Line D — NOT reverses a condition. NOT (Mark < 50) is true when the mark is 50 or more, which is a pass, so Fail would be set wrongly. It should be NOT (Mark >= 50), which is true for marks below 50.
Question 5
A DECLARE Age : INTEGER
B INPUT Age
C IF NOT Age < 0 OR Age > 120
D THEN
E OUTPUT "Accepted"
F ENDIF
Line C — The brackets are missing, so NOT only reverses Age < 0 and the OR part is worked out separately. The whole condition needs brackets: NOT (Age < 0 OR Age > 120).

Student with a class code? Join your class →