The big idea: Selection runs one block of code instead of another, depending on a condition.
The condition is always a Boolean — it works out to True or False, and nothing else.
if mark >= 70:
grade = "A"
elif mark >= 60: # Java: else if
grade = "B"
elif mark >= 50:
grade = "C"
else:
grade = "F"
print(grade)if (mark >= 70) {
grade = "A";
} else if (mark >= 60) {
grade = "B";
} else if (mark >= 50) {
grade = "C";
} else {
grade = "F";
}
System.out.println(grade);An else-if chain stops at the first match: Once a branch is taken, the rest are skipped entirely.
So a mark of 75 gives "A" and never reaches the 60 test — which is exactly why the order of the tests matters.
Free preview
This is the free notes preview
You're reading the free notes. Aimnova Pro unlocks the full study experience — and you can try it with your first topic free to keep:
- FlashcardsLock in vocabulary and key terms with spaced repetition.
- Practice questionsAnswer exam-style questions and get instant AI marking.
- Mock exams & past-paper vaultSit full mocks and see exactly how examiners award marks.
- Personalised study planA daily plan built around your exam date and weak areas.
One else-if chain
- Exactly one branch runs
- Later tests are skipped once a match is found
- Right when the cases are mutually exclusive — one grade per mark
- Faster: it stops as soon as it knows
Separate ifs
- Every condition is tested
- Several may run, or none
- Right when the cases are independent — a discount and free delivery
- Using separate ifs for exclusive cases is a common bug
# WRONG — separate ifs for exclusive cases
if mark >= 50: grade = "C"
if mark >= 60: grade = "B"
if mark >= 70: grade = "A"
# a mark of 75 sets C, then B, then A — it only works by accident
# WRONG — right structure, wrong order
if mark >= 50: grade = "C" # 75 matches here first
elif mark >= 70: grade = "A" # never reached
// WRONG — separate ifs for exclusive cases
if (mark >= 50) { grade = "C"; }
if (mark >= 60) { grade = "B"; }
if (mark >= 70) { grade = "A"; }
// a mark of 75 sets C, then B, then A — it only works by accident
// WRONG — right structure, wrong order
if (mark >= 50) { grade = "C"; } // 75 matches here first
else if (mark >= 70) { grade = "A"; } // never reachedOrder the tests from the narrowest: In a chain of ranges, start with the most restrictive and work outwards.
Testing mark >= 50 first catches every passing mark, so nothing after it can ever run. This is the single commonest selection bug.
Follow one value through the chain: only the first true test runs.
Practice with exam-style questions
Answer exam-style questions and get AI feedback that shows you exactly what examiners want to see in a full-marks response.
Relational operators
- == equal · != not equal
- < and > · <= and >=
- == compares; = assigns — mixing them is a classic error
Boolean operators
- and — both must be true
- or — at least one must be true
- not — reverses it
- The same logic as the AND, OR and NOT gates in Unit A1
Writing them well
- Brackets make the grouping obvious, even when not required
- and binds tighter than or, so a or b and c is a or (b and c)
- If you have to work it out, add the brackets
# Both must hold
if age >= 16 and has_permission:
print("Allowed")
# Either will do
if day == "Saturday" or day == "Sunday":
print("Weekend")
# Reversing a condition
if not is_member:
print("Please join first")
# A common mistake
if day == "Saturday" or "Sunday": # always true — "Sunday" alone is not a test
...// Both must hold
if (age >= 16 && hasPermission) {
System.out.println("Allowed");
}
// Either will do
if (day.equals("Saturday") || day.equals("Sunday")) {
System.out.println("Weekend");
}
// Reversing a condition
if (!isMember) {
System.out.println("Please join first");
}
// A common mistake
if (day == "Saturday") { } // compares REFERENCES, not the text — use .equalsEach side of or must be a full test: day == "Saturday" or "Sunday" does not mean what it looks like.
The second half is just a piece of text, which counts as true — so the whole condition is always true. Write the comparison out on both sides.
How this is tested — you must pick the right structure and order the conditions so each can actually be reached. It comes up two ways:
Paper 2 — working with code
- Construct selection for a described rule, 3-5 marks
- Trace which branch runs for given values
- Find the error in a chain of conditions
Paper 2 — the algorithmic-thinking question
- Decide from a rule in words with no code shown
- Explain why a branch is unreachable
The classic trap: Ordering a range chain from the widest test first. If mark >= 50 comes first, every passing mark stops there and no later branch is ever reachable — even though the code looks right.
A shop gives 20% off orders over £100, 10% off orders over £50, and free delivery on any order over £30. Write the selection structure.
Model answer plan
See the answer broken into clear points, with guidance on how each point earns marks.