Reading Code (SQA National 5 Computing Science): Revision Note

Exam code: X816 75

Robert Hampton

Written by: Robert Hampton

Reviewed by: James Woodhouse

Updated on

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

Assignment and expressions

SET, arithmetic operators, concatenation

state, calculate

Selection (IF)

IF, ELSE, ELSEIF, comparison operators

explain, describe

Complex conditions

AND, OR, NOT, combined comparisons

explain, state

Fixed loops

REPEAT X TIMES, FOR index FROM

state, complete

Conditional loops

WHILE, REPEAT UNTIL

explain, describe

1D arrays

names[index], arrays used in loops

state, explain

random

random function used to pick a value

explain, describe

round

round to n decimal places

state output

length

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!

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Robert Hampton

Author: Robert Hampton

Expertise: Computer Science Content Creator

Rob has over 16 years' experience teaching Computer Science and ICT at KS3 & GCSE levels. Rob has demonstrated strong leadership as Head of Department since 2012 and previously supported teacher development as a Specialist Leader of Education, empowering departments to excel in Computer Science. Beyond his tech expertise, Robert embraces the virtual world as an avid gamer, conquering digital battlefields when he's not coding.

James Woodhouse

Reviewer: James Woodhouse

Expertise: Computer Science & English Subject Lead

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.