← IGCSE Computer Science Paper 2

Logical operators AND, OR and NOT

AND is TRUE only when both conditions are TRUE. OR is TRUE when at least one is TRUE. NOT reverses a BOOLEAN value. Use brackets to make complex conditions clear.

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

What it does: An Answer cannot be below 0 and above 100 at once, so OR is used. Either test being TRUE makes the whole condition TRUE. The brackets group the AND test together before OR is applied, so the order of checking is clear. NOT reverses a BOOLEAN value. NOT TRUE is FALSE. NOT GameOver is TRUE while GameOver is FALSE. So the loop keeps running until GameOver becomes TRUE. AND needs both conditions to be TRUE. One of them is FALSE, so the result is FALSE. OR is TRUE when at least one condition is TRUE. The first one is TRUE, so the result is TRUE.

Common mistakes: OR is TRUE when at least one condition is TRUE, so every number passes (for example 150 is >= 0). A range check needs AND so that both conditions must be TRUE: IF Mark >= 0 AND Mark <= 100. Mark > 0 leaves out 0, which is a valid mark. The first part must be Mark >= 0 so that both 0 and 100 are accepted: Ok ← Mark >= 0 AND Mark <= 100.

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 156–165) and word search (Modules 146–165).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which condition is TRUE when Mark is 50 and the condition is Mark >= 0 AND Mark <= 100?
FALSE, because AND needs only one conditionTRUE, because both conditions are TRUE
Matches
IF Mark < 0 AND Mark > 100 THEN
↓
AND is the wrong operator. No Mark can be below 0 and above 100 at the same time, so the condition is never TRUE. It should use OR.
Applying
Meanings
Term
AND OR NOT
Meaning
AND is TRUE only when both conditions are TRUE. OR is TRUE when at least one is TRUE. NOT reverses a BOOLEAN value. Use brackets to make complex conditions clear.
Practice
GameOver ← FALSE
Testing
Gaps
IF Mark >= 0 Mark <= 100 THEN
Check Answer
Spots
1INPUT Mark
2IF Mark >= 0 OR Mark <= 100

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

The 'Camel' badge — Endurance Champion, 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 is TRUE when Mark is 50 and the condition is Mark >= 0 AND Mark <= 100?
A. TRUE, because both conditions are TRUE ✓
B. FALSE, because AND needs only one condition
AND is TRUE only when both conditions are TRUE. 50 >= 0 is TRUE and 50 <= 100 is TRUE, so the whole condition is TRUE.
2. Answer is 150. What does Answer < 0 OR Answer > 100 give?
A. TRUE, because Answer > 100 is TRUE ✓
B. FALSE, because Answer < 0 is FALSE
OR is TRUE when at least one condition is TRUE. Answer > 100 is TRUE, so it does not matter that Answer < 0 is FALSE.
3. Which range check correctly rejects marks outside 0 to 100?
A. Mark < 0 AND Mark > 100
B. Mark < 0 OR Mark > 100 ✓
No number can be below 0 and above 100 at the same time, so AND is always FALSE. OR catches either invalid case.
4. GameOver is TRUE. What is the value of NOT GameOver?
A. FALSE ✓
B. TRUE
NOT reverses a BOOLEAN value. NOT TRUE is FALSE.
5. Which loop condition keeps the game running while the game is not over?
A. WHILE GameOver DO
B. WHILE NOT GameOver DO ✓
NOT GameOver is TRUE while GameOver is FALSE. So the loop keeps running until GameOver becomes TRUE.

Match the Pairs

Mark >= 0 AND Mark <= 100 → TRUE only when Mark is at least 0 and also at most 100, so it checks a valid range
NOT GameOver → Reverses the BOOLEAN value: TRUE when GameOver is FALSE, FALSE when GameOver is TRUE
OR is TRUE when at least one condition is TRUE, so it can detect a value outside a range → Answer < 0 OR Answer > 100
Brackets make a complex condition clear by showing which part is worked out first → (Age >= 13 AND Age <= 19) OR Student = TRUE
IF Mark < 0 AND Mark > 100 THEN → AND is the wrong operator. No Mark can be below 0 and above 100 at the same time, so the condition is never TRUE. It should use OR.
IF Mark >= 0 OR Mark <= 100 THEN → OR is the wrong operator for a valid range. Every number is at least 0 or at most 100, so the condition is always TRUE. It should use AND.

Key Term

AND OR NOT
AND is TRUE only when both conditions are TRUE. OR is TRUE when at least one is TRUE. NOT reverses a BOOLEAN value. Use brackets to make complex conditions clear.

Fill in the Blanks

1. IF Mark >= 0 AND Mark <= 100 THEN OUTPUT "Valid mark" ENDIF
Hint: Type the logical operator that makes the condition TRUE only when both comparisons are 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 of the two comparisons is TRUE.
3. WHILE NOT GameOver DO OUTPUT "Keep playing" ENDWHILE
Hint: Type the logical operator that reverses the BOOLEAN value of GameOver so the loop runs while the game is still going.
4. IF NOT (Mark >= 0 AND Mark <= 100) THEN OUTPUT "Invalid" ENDIF
Hint: Type the operator that reverses the result of the whole bracketed condition.
5. IF Age >= 18 AND (HasId OR HasPass) THEN OUTPUT "Entry allowed" ENDIF
Hint: Type the logical operator inside the brackets that lets either document be enough.

Spot the Error

Question 1
A INPUT Mark
B IF Mark >= 0 OR Mark <= 100
C THEN
D OUTPUT "Valid"
E ENDIF
Line B — OR is TRUE when at least one condition is TRUE, so every number passes (for example 150 is >= 0). A range check needs AND so that both conditions must be TRUE: IF Mark >= 0 AND Mark <= 100.
Question 2
A DECLARE Mark : INTEGER
B DECLARE Ok : BOOLEAN
C INPUT Mark
D Ok ← Mark > 0 AND Mark <= 100
Line D — Mark > 0 leaves out 0, which is a valid mark. The first part must be Mark >= 0 so that both 0 and 100 are accepted: Ok ← Mark >= 0 AND Mark <= 100.
Question 3
A GameOver ← FALSE
B Lives ← 3
C WHILE GameOver DO
D INPUT Lives
E GameOver ← Lives = 0
F ENDWHILE
Line C — GameOver starts as FALSE, so WHILE GameOver is FALSE straight away and the loop never runs. NOT reverses the value so the loop runs while the game is not over: WHILE NOT GameOver DO.
Question 4
A INPUT Answer
B IF Answer < 0 AND Answer > 100
C THEN
D OUTPUT "Out of range"
E ENDIF
Line B — No number can be less than 0 and more than 100 at the same time, so AND is never TRUE. To catch a value outside the range you need OR: IF Answer < 0 OR Answer > 100.
Question 5
A INPUT Rain
B INPUT Cold
C IF NOT Rain AND Cold
D THEN
E OUTPUT "Go out"
F ENDIF
Line C — Without brackets, NOT only reverses Rain, not the whole condition. The brackets make NOT apply to (Rain AND Cold): IF NOT (Rain AND Cold).

Student with a class code? Join your class →