Programming Constructs: Sequence, Selection & Iteration (OCR A-Level CS 2.2.1)
OCR A-Level CS 2.2.1: the three building blocks of every program, namely sequence, selection (branching) and iteration, in OCR pseudocode, with trace tables and worked examples.

Free Programming Constructs revision resources (OCR A-Level Computer Science, 2.2.1)
We’ve made exam-style practice for this exact topic, free to download: Programming Constructs question sheet, mark scheme and cheat sheet. Grab them, have a go, then read the full guide below.
Every program ever written is built from just three control structures: sequence, selection and iteration (OCR calls selection "branching"). Spec point 2.2.1(a) expects you to use all three fluently, and Paper 2 is full of "complete the algorithm" and "trace the code" questions that test exactly this. I'll be honest with you: this is the most examined skill on the whole paper, so getting it automatic is the best investment you can make. Master the constructs and a huge chunk of the paper opens up.
We'll use OCR's exam-reference pseudocode throughout.

Sequence
Sequence simply means statements run one after another, top to bottom, in order. Nothing clever, but order matters, because a later line often depends on an earlier one.
You can't compute area before length and width exist. That's sequence.
Selection (branching)
Selection chooses which statements run, based on a condition. OCR's main forms are IF…ELSE and SWITCH/CASE:
The conditions are tested in order; the first one that's True runs, the rest are skipped. When you're comparing one variable against many fixed values, a switch/case is cleaner:
Iteration

Iteration (looping) repeats statements. OCR distinguishes two kinds:
Count-controlled: repeats a known number of times, using
FOR:
Condition-controlled: repeats until a condition changes, when you don't know the count in advance.
WHILEtests before the loop body (it may run zero times);DO…UNTILtests after (it always runs at least once):
This is the most important part, because examiners test it directly. Choosing the right loop is a common exam decision: known count → FOR; unknown, test-first → WHILE; unknown, run-at-least-once → DO…UNTIL.
Worked example: trace a loop with selection
Here's the kind of trace table Paper 2 loves. The algorithm sums the even numbers from 1 to 5:
Tracing each pass (MOD gives the remainder, so i MOD 2 == 0 means "even"):
i | i MOD 2 == 0? | total |
|---|---|---|
1 | False | 0 |
2 | True | 2 |
3 | False | 2 |
4 | True | 6 |
5 | False | 6 |
Final output: 6 (that's 2 + 4). Building the trace table column by column is how you avoid silly mistakes, and it is often worth marks in itself.
Common exam mistakes
These are the errors that cost easy marks, and they are all quick to fix.
WHILE vs DO…UNTIL.
WHILEmay run zero times (tests first);DO…UNTILalways runs at least once (tests last).Off-by-one in FOR loops.
for i = 1 to 5runs 5 times (1,2,3,4,5); check the bounds are inclusive.=vs==. Assignment uses=; comparison in a condition uses==. Mixing them up loses marks.Skipping the trace table. "Trace the algorithm" wants the table, with every variable's value at each step, not just the final answer.
Wrong loop choice. Use FOR only when the number of repeats is known; otherwise a condition-controlled loop.
Quick recap
Every program = sequence + selection + iteration.
Sequence: statements run in order; later lines depend on earlier ones.
Selection (branching):
IF…ELSEIF…ELSEorSWITCH/CASEchoose which code runs; conditions test in order.Iteration: count-controlled (
FOR, known count) or condition-controlled (WHILEtest-first;DO…UNTILtest-last).Trace tables: track each variable per pass, the reliable way to follow (and earn marks for) an algorithm.
Here is the habit that pays off: when you are stuck on a "trace the code" question, do not try to hold it all in your head. Draw the trace table and fill it in one row at a time. It feels slow, but it is far faster than getting it wrong, and the table itself often earns marks. Work hard now, enjoy later. I believe in you.
Frequently asked questions
What are the three programming constructs? The three programming constructs are sequence, selection and iteration. Sequence means running statements in order, selection (branching) means choosing which statements run based on a condition, and iteration means repeating statements. Every program is built from combinations of these three.
What is the difference between selection and iteration? Selection chooses which statements run based on a condition and runs them at most once per decision, using IF or SWITCH/CASE. Iteration repeats statements, either a known number of times with a FOR loop or until a condition changes with a WHILE or DO...UNTIL loop.
What is the difference between a WHILE loop and a DO...UNTIL loop? A WHILE loop tests its condition before the loop body, so it may run zero times if the condition is already false. A DO...UNTIL loop tests its condition after the body, so it always runs at least once. Choose WHILE when the loop might not need to run, and DO...UNTIL when it must run at least once.
When should I use a count-controlled loop? Use a count-controlled loop (a FOR loop) when the number of repetitions is known in advance, such as processing every item in a list of fixed length. When the number of repetitions is not known and depends on a condition, use a condition-controlled loop instead.
What is a trace table? A trace table is a way of following an algorithm by hand, writing down the value of every variable after each step or each pass of a loop. It is used to predict a program's output and to find logic errors, and "trace the algorithm" questions in Paper 2 expect the completed table.
What is the difference between = and == in OCR pseudocode? In OCR pseudocode a single = is used for assignment, giving a variable a value, while == is used for comparison inside a condition, testing whether two values are equal. Using the wrong one is a common error that changes the meaning of the code.


