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.
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
Order 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.
Practice with real exam 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
Each 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 mark-by-mark plan — for / against / judgement, with marking guidance — in study mode.