AQA GCSE Computer Science pseudo-code (8525): every command with examples
GCSE Computer Science
Start today's paperPaper resets in
Formula sheet
The card below opens today's Computer Science paper with the language reference in the drawer, so you practise reading code the way the paper gives it. The tables follow, in our own layout. We read AQA's 2024 guidance, which AQA says may be updated, so check its latest version before you rely on anything here. AQA describes it as a resource to help you prepare, and does not say it is printed in the paper.
GCSE Computer Science
Comments, variables and constants
Constant names are always written in capitals.
| Concept | Keywords and symbols | Example |
|---|---|---|
| Comment | # | # a note |
| Assignment | name ← expression | b ← a + 1 |
| Constant | CONSTANT NAME ← value | CONSTANT CLASS_SIZE ← 23 |
Operators
The / symbol is used for division. Use DIV for integer division.
| Concept | Keywords and symbols | Example |
|---|---|---|
| Arithmetic | + - * / | a + b * c |
| Integer division | DIV | 9 DIV 5 is 1 |
| Remainder | MOD | 9 MOD 5 is 4 |
| Relational | < > = ≠ ≤ ≥ | qty ≠ 7 |
| Boolean | AND OR NOT | NOT (a < b) |
Iteration
The loop counter exists only inside the FOR loop. If STEP is left out it is 1. An array item cannot be changed through FOR-IN.
| Concept | Keywords and symbols | Example |
|---|---|---|
| Repeat until | REPEAT ... UNTIL condition | REPEAT ... UNTIL a = 4 |
| While | WHILE condition ... ENDWHILE | WHILE a < 4 |
| Count controlled | FOR a ← 1 TO 3 [STEP n] ... ENDFOR | FOR a ← 5 TO 1 STEP -2 |
| Each character | FOR char IN string ... ENDFOR | FOR char IN message |
| Each array element | FOR item IN array ... ENDFOR | FOR prime IN primes |
Selection
IF statements can be nested inside the THEN part, the ELSE part or both.
| Concept | Keywords and symbols | Example |
|---|---|---|
| If | IF condition THEN ... ENDIF | IF a = 1 THEN |
| If else | IF ... THEN ... ELSE ... ENDIF | IF (a MOD 2) = 0 THEN |
| Else if | IF ... ELSE IF ... ELSE ... ENDIF | ELSE IF a = 2 THEN |
Arrays and records
Exam questions start indexing at 0 unless a question says otherwise.
| Concept | Keywords and symbols | Example |
|---|---|---|
| Array | name ← [a, b, c] | primes ← [2, 3, 5] |
| Read an element | name[i] | primes[0] |
| Update an element | name[i] ← value | primes[2] ← 7 |
| Two dimensions | name[i][j] | table[3][1] |
| Length | LEN(name) | LEN(primes) |
| Record | RECORD name ... ENDRECORD | RECORD Car |
| Field of a record | variable.field | myCar.model ← "Fiesta" |
Subroutines
A subroutine with RETURN is a function. One without is a procedure.
| Concept | Keywords and symbols | Example |
|---|---|---|
| Define | SUBROUTINE name(parameters) ... ENDSUBROUTINE | SUBROUTINE add(a, b) |
| Return a value | RETURN expression | RETURN result |
| Call a procedure | name(parameters) | showAdd(2, 3) |
| Call a function | variable ← name(parameters) | answer ← add(2, 3) |
Strings, conversion, input and output
The end position in SUBSTRING is included. RANDOM_INT includes both ends.
| Concept | Keywords and symbols | Example |
|---|---|---|
| Length | LEN(string) | LEN('keyboard') is 8 |
| Position of a character | POSITION(string, char) | POSITION('keyboard', 'b') |
| Substring | SUBSTRING(start, end, string) | SUBSTRING(1, 4, 'keyboard') |
| Concatenation | + | 'key' + 'board' |
| String to number | STRING_TO_INT STRING_TO_REAL | STRING_TO_INT('16') |
| Number to string | INT_TO_STRING REAL_TO_STRING | INT_TO_STRING(16) |
| Character codes | CHAR_TO_CODE CODE_TO_CHAR | CHAR_TO_CODE('a') is 97 |
| Input | USERINPUT | a ← USERINPUT |
| Output | OUTPUT value, value | OUTPUT a, g |
| Random integer | RANDOM_INT(low, high) | RANDOM_INT(1, 6) |
Reading AQA pseudo-code
Read the code from the top, one line at a time, and keep a table of the variables. The ← arrow means "becomes". Trace this short program:
total ← 0
FOR n ← 2 TO 10 STEP 4
total ← total + n
ENDFOR
OUTPUT totalThe loop runs for n = 2, 6 and 10, because 14 is past the limit. The total goes 2, then 8, then 18, so the program outputs 18.
| n | total |
|---|---|
| 2 | 2 |
| 6 | 8 |
| 10 | 18 |
Dividing, strings and a function
23 DIV 5 is 4 and 23 MOD 5 is 3, because 23 = 4 × 5 + 3. In SUBSTRING(1, 4, 'keyboard') the characters at positions 1, 2, 3 and 4 are taken, which gives 'eybo': position 0 is k, and the end position is included. This function returns a value, so it is a function:
SUBROUTINE isEven(n)
IF (n MOD 2) = 0 THEN
RETURN True
ELSE
RETURN False
ENDIF
ENDSUBROUTINE
OUTPUT isEven(17)17 MOD 2 is 1, so the condition is false and the program outputs False.
What the pseudo-code guide does not give you
- Which structure to use. It lists WHILE, REPEAT-UNTIL and FOR loops. Choosing the right one for a question is yours to do.
- Algorithms. Searching, sorting and the other algorithms in the specification are not written out. You need to know how they work.
- Flowcharts and trace tables. Those skills sit outside the pseudo-code guide.
- Your own programming language. It does not cover Python or any other language you use for programming tasks.
- Errors. It does not say what a syntax error or a logic error looks like, so learn to spot both.
How to use it in the exam
- Read the whole program once before you trace it.
- Make a table with a column for each variable and one row for each pass of a loop.
- Remember that arrays and strings start at index 0 unless the question says otherwise.
- Check boundaries: a FOR loop to 3 includes 3, and SUBSTRING includes its end position.
- Write your own answers clearly and consistently: AQA says that is the only direction.
AQA pseudo-code and other boards' languages
OCR uses its own Exam Reference Language in J277 papers, with keywords such as endif, next and MOD, and Pearson Edexcel uses a subset of Python. Use the one your board names. Read our OCR Exam Reference Language guide for the OCR version. For the boards, papers and grade boundaries, see our GCSE Computer Science guide.
Use the sheet with today's paper
Uni-Sine publishes a free daily paper for GCSE Computer Science. It is a short timed paper of 8 questions worth 25 to 35 marks, not a full AQA paper, and it is not written by AQA. Open the reference, set a timer and write your trace table at the top of each answer. After marking, look at any question where you used the wrong loop or the wrong index.
Common mistakes
- Off by one in a FOR loop. FOR a ← 1 TO 3 runs 3 times, and includes 3.
- Mixing up DIV and MOD. DIV is the whole number quotient and MOD is the remainder.
- Counting from 1. Array and string positions start at 0 unless a question says so.
- Forgetting the end keyword. Every IF has an ENDIF, and every WHILE has an ENDWHILE.
- Reading ← as equals. ← assigns a value. = compares two values.
- Ignoring that SUBSTRING includes its end. SUBSTRING(1, 4, text) takes four characters.
Exam answers
The answers and a worked mark scheme come with today's paper once it is marked. Sit the paper with the sheet open beside you, mark it, and the worked answers show which line of the sheet each question wanted. We do not publish official or past paper answers.
Common questions
What is the AQA pseudo-code?
Do I have to write my answers in AQA pseudo-code?
Do exam questions count from 0 or 1?
What is the difference between DIV and MOD?
What makes a subroutine a function in AQA pseudo-code?
Revision cards
Say the answer first, then flip the card to check it.
Where to go next
- Solve it
Code Editor
Write and run code right in your browser
Open the tool - Learn it
Programming Languages
Compiled vs interpreted, paradigms and the evolution of how we talk to machines
Start the course - Test it
GCSE Computer Science
A new exam-style paper every day, with instant marking and a mark scheme
Start today's paper