SQA reference language for Computing Science: what the exam code means
National 5 Computing Science
Start today's paperHigher Computing Science
Start today's paperPapers reset in
Formula sheet
It is a document, not a sheet in the exam: SQA publishes it and the papers use it. The card below opens today's Higher Computing Science paper with our summary in the drawer, so you can check what a construct means while you read the code. The summary follows in our own layout and words, grouped by what the code does. Check it against the full SQA document, dated September 2016, before you rely on it.
National 5 Computing Science
Types and values
| Reference language | What it means | Level |
|---|---|---|
| INTEGER, REAL, BOOLEAN, CHARACTER | The base types: whole numbers, decimals, true or false, and a single character | All |
| STRING | Text, which is an array of characters | All |
| ARRAY OF INTEGER | A list of values that are all of one type | All |
| [ 10, 20, 30 ] | An array value, with the first item at position 0 | All |
| RECORD Person IS { STRING name, INTEGER age } | A named record type, with one value for each field | Higher, Advanced Higher |
| { name = "Fred", age = 42 } | A record value | Higher, Advanced Higher |
Variables and assignment
| Reference language | What it means | Level |
|---|---|---|
| DECLARE total INITIALLY 0 | Creates a variable and gives it a starting value | All |
| DECLARE x AS INTEGER INITIALLY 0 | The same, with the type written out | All |
| SET total TO total + 1 | Changes the value of a variable that exists | All |
Conditions
| Reference language | What it means | Level |
|---|---|---|
| IF .. THEN .. END IF | Runs the commands only when the condition is true | All |
| IF .. THEN .. ELSE .. END IF | Chooses between two sets of commands | All |
Loops
| Reference language | What it means | Level |
|---|---|---|
| WHILE .. DO .. END WHILE | Repeats while the condition is true, checked before each pass | All |
| REPEAT .. UNTIL .. | Repeats until the condition is true, checked after each pass | All |
| REPEAT 5 TIMES .. END REPEAT | Repeats a fixed number of times | All |
| FOR i FROM 0 TO 9 DO .. END FOR | Counts from the start value to the end value | All |
| FOR i FROM 0 TO 9 STEP 3 DO .. END FOR | The same, in steps of 3 | All |
| FOR EACH item FROM list DO .. END FOR EACH | Goes through every value in an array or other collection | All |
Input and output
| Reference language | What it means | Level |
|---|---|---|
| RECEIVE x FROM KEYBOARD | Reads a value into an existing variable | All |
| DECLARE x INITIALLY FROM KEYBOARD | Creates a variable from the first value read | All |
| SEND x TO DISPLAY | Shows a value | All |
| OPEN, CLOSE, CREATE | File operations | Higher, Advanced Higher |
Operations
| Reference language | What it means | Level |
|---|---|---|
| + - * / ^ | Add, subtract, multiply, divide and raise to a power | All |
| MOD | The remainder after a division | All |
| & | Joins strings, as in "Total: " & total | All |
| = ≠ < ≤ > ≥ | Comparisons | All |
| AND OR NOT | Logical operators | All |
Subprograms
| Reference language | What it means | Level |
|---|---|---|
| move( sprite, "up", 0.5 ) | A call to a subprogram, with its parameters in brackets | All |
| PROCEDURE id ( parameters ) .. END PROCEDURE | A subprogram that does something and returns nothing | Higher, Advanced Higher |
| FUNCTION id ( parameters ) RETURNS type .. RETURN expression .. END FUNCTION | A subprogram that returns a value | Higher, Advanced Higher |
Object-oriented programming
| Reference language | What it means | Level |
|---|---|---|
| CLASS .. IS { .. } METHODS .. END CLASS | Defines a class with its fields and methods | Advanced Higher |
| CLASS .. INHERITS .. WITH { .. } METHODS .. END CLASS | Defines a subclass | Advanced Higher |
| CONSTRUCTOR .. END CONSTRUCTOR | The method that creates an object | Advanced Higher |
| OVERRIDE CONSTRUCTOR .. END CONSTRUCTOR | A constructor in a subclass that replaces the parent's | Advanced Higher |
Comments and elisions
| Reference language | What it means | Level |
|---|---|---|
| # a comment | A note for the reader, ignored by the program | All |
| < .. > | An elision: part of the code written in English, not in the reference language | All |
What the reference language is not
- Not a language you must write. The specifications say candidates are not expected to write code in the reference language, and that answers may use any programming language. Marks are for demonstrating understanding, not for correct syntax.
- Not a list of every function. A question may use its own subprograms, such as getColour or move, and says what they do. The language only gives the shape of the code.
- Not formal for everything. The elision < .. > lets a question describe part of the code in English.
- Not a replacement for knowledge. To explain what a program does, you still need to understand loops, arrays, records, standard algorithms and (at Advanced Higher) objects.
How the papers use the reference language
The course specifications say the questions assessing programming are expressed in the reference language. In the 2027 timetable all three papers are on Thursday 27 May: National 5 from 09:00 to 10:30, Higher from 09:00 to 11:00, and Advanced Higher from 09:00 to 11:00 (Exam Timetable 2027, version 02). The specifications give the question paper 80 marks at National 5, 80 at Higher and 55 at Advanced Higher. Our guides cover the courses: National 5, Higher and Advanced Higher.
Reading reference language under exam pressure
- Read the declarations first, so you know every variable and its starting value.
- Work through the loop by hand, with a table of the variables after each pass.
- Check the loop condition: WHILE tests before a pass and REPEAT UNTIL tests after one.
- Write what the program does in one sentence, then answer the question in that sentence.
Tracing a loop
What does this code display?
DECLARE marks INITIALLY [ 45, 62, 58, 71 ]
DECLARE total INITIALLY 0
FOR EACH mark FROM marks DO
SET total TO total + mark
END FOR EACH
SEND "Average: " & total / 4 TO DISPLAYFOR EACH takes each value in marks in turn. Keep a table of total after each pass:
| Pass | mark | total after the pass |
|---|---|---|
| 1 | 45 | 45 |
| 2 | 62 | 107 |
| 3 | 58 | 165 |
| 4 | 71 | 236 |
Then 236 ÷ 4 = 59, so the program displays Average: 59. The & joins the text to the number. In words, it finds the average of four marks.
A condition inside a loop
What does this code display?
DECLARE count INITIALLY 0
FOR n FROM 1 TO 10 DO
IF n MOD 3 = 0 THEN
SET count TO count + 1
END IF
END FOR
SEND count TO DISPLAYMOD gives the remainder, so n MOD 3 = 0 is true when n is a multiple of 3. Between 1 and 10 those are 3, 6 and 9, so count is 3 and the program displays 3. It counts the multiples of 3.
Practise tracing code in the Search Algorithms course, then press Mark.
Type how many checks linear search makes to find a target in a random list, or to give up.
Press Mark to have your answer marked in the Search Algorithms course.
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 each question wanted. We do not publish official or past paper answers.
Use the sheet with today's paper
Uni-Sine publishes a free daily paper for National 5 Computing Science and Higher Computing Science. It is a short timed paper of 8 questions worth 25 to 35 marks, not a full SQA paper and not set by SQA. Many schools set a longer prelim in winter: see our prelims guide. Open the sheet, set a timer, and write the line you use at the start of each answer.
Common mistakes
- Skipping the trace. Guessing the output from the code's shape loses marks. Write the variables out after each pass.
- Mixing up WHILE and REPEAT UNTIL. WHILE can run zero times. REPEAT UNTIL always runs at least once.
- Starting at 1. Array positions start at 0, as in allTimes[ 0 ].
- Ignoring the declaration. The starting value of total changes every answer.
- Describing the lines instead of the purpose. Say what the program is for, such as finding the average or counting multiples.
Common questions
What is the SQA reference language?
Do I have to write in the SQA reference language?
Is the reference language the same as pseudocode?
Does Advanced Higher use more of the reference language?
Where can I read the SQA reference language?
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
Search Algorithms
Linear, binary, depth-first and beyond: find data fast with the right algorithm
Start the course - Test it
National 5 Computing Science
A new exam-style paper every day, with instant marking and a mark scheme
Start today's paper