REVISION GUIDE: BOOLEAN LOGIC & SELECTION
| Learning goal: Use Boolean values and logical operators to make a program take an action only when the correct combination of conditions is true. |
1. Boolean data and variables
Boolean: A data type with only two possible values: TRUE or FALSE. It is useful for representing states such as whether a user is logged in, a machine is ready, or a payment is complete.
Boolean variable: A named storage location that holds a TRUE/FALSE value. For example, IsLoggedIn = TRUE means the user is currently logged in.
Important: A Boolean variable can be tested directly in a condition. Some languages also allow an explicit comparison, such as IF IsLoggedIn == TRUE
2. Logical operators: AND, OR and NOT
Logical operators combine or change Boolean conditions:
| Operator | Meaning | When is result TRUE? |
| AND | Both conditions must be true. | Only when the left AND right conditions are TRUE. |
| OR | At least one condition must be true. | When either condition, or both, are TRUE. |
| NOT | Reverses a Boolean value. | NOT TRUE becomes FALSE; NOT FALSE becomes TRUE. |
Quick example: A school website allows a learner to open a quiz only if their account is active AND they have joined the course. If either condition is FALSE, access is denied.
Another example: A device displays a warning if its battery is low OR its temperature is too high. Either condition is enough to display the warning.
3. Selection: IF, ELSE IF and ELSE
Selection: A programming structure that chooses which instructions to run based on whether a condition is TRUE or FALSE.
IF condition THEN
instructions when TRUE
ELSE
instructions when FALSE
ENDIF
Example (different context): A parcel locker opens only when a valid access code has been entered and the locker is available.
IF CodeValid AND LockerAvailable THEN
OUTPUT “Locker opened”
ELSE
OUTPUT “Access denied”
ENDIF
4. Combining conditions correctly
When a rule says “A must be true, and either B or C must be true”, group B and C together with brackets:
IF A AND (B OR C) THEN
perform the action
ENDIF
Why brackets matter: They make it clear that the OR is evaluated as one grouped condition. Without brackets, the program may interpret the logic differently and perform the action in situations that should not qualify.
5. Step-by-step exam method
- Underline the required action – What should the program do when the rule is satisfied?
- List the conditions – Identify every Boolean variable that must be checked.
- Translate the rule – Use AND for “both/all”; use OR for “either/at least one”; use NOT for “not”.
- Add brackets – Group conditions when the wording contains a combined rule such as “A and either B or C”.
- Write selection code – Use IF … THEN and call the named procedure or perform the required instruction inside the correct block.
- Trace test values – Try TRUE and FALSE combinations to check that the action happens only in valid cases.
6. Keywords and common mistakes
Remember: Boolean • TRUE • FALSE • condition • selection • IF • ELSE • AND • OR • NOT • brackets • procedure call.
Avoid: using OR when all conditions are required; using AND when only one condition is needed; forgetting to check every required variable; missing brackets; calling the procedure outside the condition; confusing a variable name with a text value.
Exam tip: Test your logic with a small truth table or a few TRUE/FALSE combinations before finishing.
