Uni-Sine
Scottish examsHigher

SQA reference language for Computing Science: what the exam code means

Papers 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.

Formula sheet

National 5 Computing Science

Open formula sheet

Types and values

Reference languageWhat it meansLevel
INTEGER, REAL, BOOLEAN, CHARACTERThe base types: whole numbers, decimals, true or false, and a single characterAll
STRINGText, which is an array of charactersAll
ARRAY OF INTEGERA list of values that are all of one typeAll
[ 10, 20, 30 ]An array value, with the first item at position 0All
RECORD Person IS { STRING name, INTEGER age }A named record type, with one value for each fieldHigher, Advanced Higher
{ name = "Fred", age = 42 }A record valueHigher, Advanced Higher

Variables and assignment

Reference languageWhat it meansLevel
DECLARE total INITIALLY 0Creates a variable and gives it a starting valueAll
DECLARE x AS INTEGER INITIALLY 0The same, with the type written outAll
SET total TO total + 1Changes the value of a variable that existsAll

Conditions

Reference languageWhat it meansLevel
IF .. THEN .. END IFRuns the commands only when the condition is trueAll
IF .. THEN .. ELSE .. END IFChooses between two sets of commandsAll

Loops

Reference languageWhat it meansLevel
WHILE .. DO .. END WHILERepeats while the condition is true, checked before each passAll
REPEAT .. UNTIL ..Repeats until the condition is true, checked after each passAll
REPEAT 5 TIMES .. END REPEATRepeats a fixed number of timesAll
FOR i FROM 0 TO 9 DO .. END FORCounts from the start value to the end valueAll
FOR i FROM 0 TO 9 STEP 3 DO .. END FORThe same, in steps of 3All
FOR EACH item FROM list DO .. END FOR EACHGoes through every value in an array or other collectionAll

Input and output

Reference languageWhat it meansLevel
RECEIVE x FROM KEYBOARDReads a value into an existing variableAll
DECLARE x INITIALLY FROM KEYBOARDCreates a variable from the first value readAll
SEND x TO DISPLAYShows a valueAll
OPEN, CLOSE, CREATEFile operationsHigher, Advanced Higher

Operations

Reference languageWhat it meansLevel
+ - * / ^Add, subtract, multiply, divide and raise to a powerAll
MODThe remainder after a divisionAll
&Joins strings, as in "Total: " & totalAll
= ≠ < ≤ > ≥ComparisonsAll
AND OR NOTLogical operatorsAll

Subprograms

Reference languageWhat it meansLevel
move( sprite, "up", 0.5 )A call to a subprogram, with its parameters in bracketsAll
PROCEDURE id ( parameters ) .. END PROCEDUREA subprogram that does something and returns nothingHigher, Advanced Higher
FUNCTION id ( parameters ) RETURNS type .. RETURN expression .. END FUNCTIONA subprogram that returns a valueHigher, Advanced Higher

Object-oriented programming

Reference languageWhat it meansLevel
CLASS .. IS { .. } METHODS .. END CLASSDefines a class with its fields and methodsAdvanced Higher
CLASS .. INHERITS .. WITH { .. } METHODS .. END CLASSDefines a subclassAdvanced Higher
CONSTRUCTOR .. END CONSTRUCTORThe method that creates an objectAdvanced Higher
OVERRIDE CONSTRUCTOR .. END CONSTRUCTORA constructor in a subclass that replaces the parent'sAdvanced Higher

Comments and elisions

Reference languageWhat it meansLevel
# a commentA note for the reader, ignored by the programAll
< .. >An elision: part of the code written in English, not in the reference languageAll

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

  1. Read the declarations first, so you know every variable and its starting value.
  2. Work through the loop by hand, with a table of the variables after each pass.
  3. Check the loop condition: WHILE tests before a pass and REPEAT UNTIL tests after one.
  4. 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 DISPLAY

FOR EACH takes each value in marks in turn. Keep a table of total after each pass:

Passmarktotal after the pass
14545
262107
358165
471236

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 DISPLAY

MOD 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?
It is the standard notation SQA uses to present code in National 5, Higher and Advanced Higher Computing Science question papers. It is written in capitals, such as DECLARE and FOR EACH.
Do I have to write in the SQA reference language?
No. The specifications say candidates are not expected to write code in it, and that you can use any programming language. Marks are for understanding, not for correct syntax.
Is the reference language the same as pseudocode?
SQA's document says earlier versions called it pseudocode, but it prefers reference language, because it is formally defined.
Does Advanced Higher use more of the reference language?
Yes. It adds classes, inheritance and constructors for object-oriented programming. Higher adds records, files, procedures and functions to what National 5 uses.
Where can I read the SQA reference language?
SQA's document Reference language for Computing Science question papers is on the Qualifications Scotland website, dated September 2016.

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
Read next
Scotland · HigherHigher Computing Science grade boundaries 2025: A, B, C, DHigher Computing Science grade boundaries 2025 from the SQA: A needed 82 of 120, B 71, C 60 and D 49, with 42.1% getting an A, and 2024 compared.