Variables, sequence, selection and iteration
These four ideas are the heart of programming. Every algorithm — no matter how complex — is built from a combination of variables, sequences, selections (decisions) and iterations (loops).
Variables and constants
A variable is a named storage location whose value can change as the program runs.
SET score TO 0
SET score TO score + 1
A constant is a name whose value is fixed throughout execution. Use constants for values that should never change (e.g. VAT rate, pi). They protect you against accidental edits and document intent.
CONSTANT VAT TO 0.20
SET price TO net * (1 + VAT)
In AQA pseudocode, the syntax may also appear as vatRate ← 0.20. The arrow and SET ... TO are interchangeable.
Naming conventions — use clear, lower-case-camelCase names: totalScore, isLoggedIn, numberOfAttempts. Avoid single letters except for loop counters i, j.
Sequence
Statements run in the order written, top to bottom. This is the simplest construct.
USERINPUT name
USERINPUT age
OUTPUT "Hello " + name
OUTPUT "You are " + age
If you swap the first two lines, the meaning changes — sequence matters.
Selection (IF / ELSE)
A decision picks between alternatives based on a condition.
USERINPUT score
IF score >= 70 THEN
OUTPUT "Distinction"
ELSEIF score >= 50 THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
Boolean conditions use comparison operators (=, !=, <, <=, >, >=) and logical operators (AND, OR, NOT).
IF age >= 18 AND hasLicense = true THEN
OUTPUT "Can drive"
ENDIF
Iteration — counted (FOR) and conditional (WHILE)
A counted loop (FOR) repeats a fixed number of times.
FOR i FROM 1 TO 10
OUTPUT i * i
ENDFOR
This prints 1, 4, 9, …, 100. The loop counter i runs from 1 to 10 inclusive.
A conditional loop (WHILE) repeats as long as a condition is true. The condition is checked before each iteration, so the body might not run at all if the condition is false initially.
USERINPUT pin
WHILE pin != 1234
OUTPUT "Wrong PIN. Try again."
USERINPUT pin
ENDWHILE
OUTPUT "Access granted"
If the user enters the right PIN first time, the loop body never executes.
A REPEAT … UNTIL loop (post-test) checks the condition after the body — so the body always runs at least once. AQA pseudocode uses REPEAT … UNTIL condition.
Choosing FOR or WHILE
- You know how many times in advance → FOR.
- The number depends on input or a condition during execution → WHILE.
E.g. iterating through every element of a 10-item array → FOR. Reading lines until a special "end" marker → WHILE.
Combining the constructs
SET total TO 0
SET count TO 0
USERINPUT n
WHILE n != 0
IF n > 0 THEN
SET total TO total + n
SET count TO count + 1
ENDIF
USERINPUT n
ENDWHILE
IF count > 0 THEN
OUTPUT "Average: " + (total / count)
ELSE
OUTPUT "No positive numbers entered"
ENDIF
This nests selection inside a loop, then uses another selection to handle the edge case of no input.
Common pitfalls
- Off-by-one errors.
FOR i FROM 1 TO 10runs 10 times, not 9 or 11. - Forgetting to update the loop variable in a WHILE — gives an infinite loop.
- Using = instead of == in some languages (Python:
==for comparison;=for assignment). AQA pseudocode uses=for both, by context. - Mixing AND/OR.
age >= 18 AND age <= 65is correct;age >= 18 OR age <= 65is true for everyone. - Reusing a variable name for two different purposes — confusing.
➜Try this— Quick check
Trace this program by hand for input 5:
USERINPUT n
SET total TO 0
FOR i FROM 1 TO n
SET total TO total + i
ENDFOR
OUTPUT total
Output: 15 (1+2+3+4+5).
AI-generated · claude-opus-4-7 · v3-deep-computer-science