← IGCSE Computer Science Paper 2

IF with a compound condition

A compound condition joins tests with AND, OR or NOT so one IF checks several things at once. AND needs both tests true; OR needs at least one true.

Understanding IF with a compound condition in IGCSE Computer Science Paper 2

What it does: Instead of an IF inside another IF, the AND checks both rules in a single condition, so the code runs only when both are true. A weekend is Saturday or Sunday, so only one test needs to be true. That is the job of OR, not AND. Both tests must be true, so use AND. With OR, almost every number passes (for example 5 is <= 19, and 50 is >= 13). No age is both under 12 and over 65. Qualifying for either group is enough, so use OR. Each side of AND must be a complete test. You must repeat the variable name: Mark <= 100.

Common mistakes: The IF line is missing THEN. A compound condition still needs THEN after it: IF Age >= 8 AND Ok = "Y" THEN. Each side of AND must be a full test. <= 19 has no variable, so it should be Age <= 19.

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 369–378) and word search (Modules 358–378).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which IF checks that Age is from 13 to 19 inclusive (a teenager)?
IF Age >= 13 AND Age <= 19 THENIF Age >= 13 OR Age <= 19 THEN
Matches
IF Age >= 13 AND <= 19 THEN
↓
The second test is missing the variable name. Each side of AND needs a full test, so it should be Age <= 19.
Applying
Meanings
Term
IF Age >= 13 AND Age <= 19 THEN
Meaning
A compound condition joins tests with AND, OR or NOT so one IF checks several things at once. AND needs both tests true; OR needs at least one true.
Practice
IF Age >= 13 AND Age <= 19 THEN
Testing
Gaps
IF Age >= 13 Age <= 19 THEN
Check Answer
Spots
3// Both must be true
4IF Age >= 8 AND Ok = "Y"

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

The 'Moray Eel' badge — Lurking Debugger, 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 checks that Age is from 13 to 19 inclusive (a teenager)?
A. IF Age >= 13 OR Age <= 19 THEN
B. IF Age >= 13 AND Age <= 19 THEN ✓
Both tests must be true, so use AND. With OR, almost every number passes (for example 5 is <= 19, and 50 is >= 13).
2. Which IF accepts either a capital or a lowercase Y?
A. IF Answer = "Y" OR Answer = "y" THEN ✓
B. IF Answer = "Y" AND Answer = "y" THEN
Answer can only hold one value at a time, so it can never be both "Y" and "y". Only one test needs to be true, so use OR.
3. True or false: in IF Score > 50 AND Score < 80 THEN, the condition is true when Score is 50.
A. True
B. False ✓
50 is not greater than 50, so the first test fails. AND needs both tests to be true.
4. Which single IF does the same job as two nested IFs: IF Age >= 13 THEN, then IF Age <= 19 THEN?
A. IF Age >= 13 AND Age <= 19 THEN ✓
B. IF Age >= 13 OR Age <= 19 THEN
Nested IFs mean the inner test only runs if the outer one is true. That is the same as AND.
5. A cinema gives a discount to children under 12 or people over 65. Which condition is correct?
A. IF Age < 12 OR Age > 65 THEN ✓
B. IF Age < 12 AND Age > 65 THEN
No age is both under 12 and over 65. Qualifying for either group is enough, so use OR.

Match the Pairs

IF Age >= 13 AND Age <= 19 THEN → Runs the code only when Age is between 13 and 19 inclusive, because both tests must be true
IF Answer = "Y" OR Answer = "y" THEN → Runs the code when the answer is a capital Y or a lowercase y, because only one test needs to be true
One IF with AND can replace two nested IFs that must both be true → IF Score >= 50 AND Attendance >= 90 THEN
Use OR when any one of several rules is enough to run the code → IF Day = "Sat" OR Day = "Sun" THEN
IF Age >= 13 AND <= 19 THEN → The second test is missing the variable name. Each side of AND needs a full test, so it should be Age <= 19.
IF Answer = "Y" AND Answer = "y" THEN → AND is the wrong operator. Answer cannot be both Y and y at once, so the condition is never true. It should use OR.

Key Term

IF Age >= 13 AND Age <= 19 THEN
A compound condition joins tests with AND, OR or NOT so one IF checks several things at once. AND needs both tests true; OR needs at least one true.

Fill in the Blanks

1. IF Age >= 13 AND Age <= 19 THEN
Hint: Type the logical operator that needs both tests to be true.
2. IF Answer = "Y" OR Answer = "y" THEN
Hint: Type the logical operator that needs at least one test to be true.
3. IF Age >= 13 AND Age <= 19 THEN OUTPUT "Teenager" ENDIF
Hint: Type the relational operator that sets the upper limit of the age range (19 or less).
4. IF NOT (Age < 13) THEN OUTPUT "Not a child" ENDIF
Hint: Type the logical operator that reverses the result of a test.
5. IF Score < 0 OR Score > 100 THEN OUTPUT "Invalid" ENDIF
Hint: A score is invalid if either test is true, so type the operator that needs only one.

Spot the Error

Question 1
A INPUT Age
B INPUT Ok
C // Both must be true
D IF Age >= 8 AND Ok = "Y"
E OUTPUT "Enter"
F ENDIF
Line D — The IF line is missing THEN. A compound condition still needs THEN after it: IF Age >= 8 AND Ok = "Y" THEN.
Question 2
A INPUT Age
B // Teenager: 13 to 19
C IF Age >= 13 AND <= 19 THEN
D OUTPUT "Teenager"
E ENDIF
Line C — Each side of AND must be a full test. <= 19 has no variable, so it should be Age <= 19.
Question 3
A INPUT Ans
B IF Ans = "Y" OR "y" THEN
C OUTPUT "Continue"
D ENDIF
Line B — OR cannot join a test to a bare value. Both sides need a full comparison: Ans = "Y" OR Ans = "y".
Question 4
A IF Mk >= 0 OR Mk <= 100 THEN
B OUTPUT "Valid"
C ELSE
D OUTPUT "Invalid"
E ENDIF
Line A — A valid mark must be at least 0 AND at most 100. With OR every number passes, so it must be AND.
Question 5
A IF Age NOT < 13 THEN
B OUTPUT "13 or older"
C ENDIF
Line A — NOT goes in front of the whole condition, not in the middle of a comparison. It should be IF NOT (Age < 13) THEN.

Student with a class code? Join your class →