Reading Code (SQA National 5 Computing Science): Revision Note
Exam code: X816 75
Reading code
Students are expected to understand unseen pseudocode that uses the standard SDD constructs
The exam will give students a short program and can ask them to explain:
What it does
How it works
What output it produces
This skill is about following the logic, tracking variables, and recognising selection, loops, arrays, and built in functions
Students should focus on how values change, how conditions are evaluated, and how each construct affects the flow of the program
Quick recap
Construct | What to look for in code | Typical question words |
|---|---|---|
SET, arithmetic operators, concatenation | state, calculate | |
IF, ELSE, ELSEIF, comparison operators | explain, describe | |
AND, OR, NOT, combined comparisons | explain, state | |
REPEAT X TIMES, FOR index FROM | state, complete | |
WHILE, REPEAT UNTIL | explain, describe | |
names[index], arrays used in loops | state, explain | |
random function used to pick a value | explain, describe | |
round to n decimal places | state output | |
length of string or array | state, calculate |
Examiner Tips and Tricks
Try to come up with a strategy, a tick list for code reading
I would suggest:
Find the inputs and outputs
Circle RECEIVE lines
Underline SEND lines
Track the variables
Highlight where each variable is first set
Note if it is updated inside a loop
Spot the constructs
Where are the IFs
Where are the loops
Are there any logical operators or predefined functions
Trace a simple example
Pick easy input values
Use a quick trace table for loops and running totals
Answer the question using the code
If the question asks for an explanation, write what the code does in plain English, not line by line narration
Example 1: Selection and logical operator
Line 1 RECEIVE age FROM (INTEGER) KEYBOARD
Line 2 RECEIVE member FROM (BOOLEAN) KEYBOARD
Line 3 IF age >= 18 AND member = TRUE THEN
Line 4 SEND "Full access" TO DISPLAY
Line 5 ELSE
Line 6 SEND "Limited access" TO DISPLAY
Line 7 END IF
Possible question could include:
State the output when age is 20 and member is TRUE
State the output when age is 16 and member is TRUE
Explain in your own words what this code does
A model explanation could include:
"This code asks for an age and whether the person is a member, if they are at least 18 and a member they get full access, otherwise they only get limited access"
Example 2: Fixed loop, running total, length
Line 1 DECLARE total INITIALLY 0
Line 2 REPEAT 3 TIMES
Line 3 RECEIVE score FROM (INTEGER) KEYBOARD
Line 4 SET total TO total + score
Line 5 END REPEAT
Line 6 SEND "Average is " & ROUND(total / 3, 1) TO DISPLAY
Questions could include:
Explain what the variable total is used for
State the output when the scores entered are 10, 12, 11
Name the standard algorithm used in lines 2 to 4
Example 3: 1D array and random
Line 1 DECLARE prizes INITIALLY ["Book","Voucher","Headphones","Game"]
Line 2 SET index TO RANDOM(0,3)
Line 3 SEND "You won a " & prizes[index] TO DISPLAY
Questions:
State one possible output
Explain how the random function is being used in this code
Name the data structure used in line 1
Unlock more, it's free!
Did this page help you?