Oakling Secondary ScholarsOakling Secondary ScholarsSign inStart free

Tracing code for GCSE Computer Science

GCSE Computer Science, Programming. Usually met in years 9 to 11.

Read short programs in pseudocode and work out what they output, with variables, loops, selection and arrays.

What you practise

Starts with a few assignments and builds to loops over arrays. Programs are written in exam-style pseudocode. Practice moves up a level when a round goes well and down when it does not.

Sample questions

Each sample comes with the method and the reason every wrong option is wrong. Real practice rounds are ten questions at your level.

Sample question, level 2 of 5

What does this program output? (DIV is whole-number division; MOD is the remainder.)

n ← 35
OUTPUT n MOD 6
  1. 1
  2. 5
  3. 5.83
  4. 6
  5. 29
Show the answer and method

Answer: B, 5

The method: 35 ÷ 6 = 5 remainder 5. So 35 DIV 6 = 5 and 35 MOD 6 = 5. The output is 5.

Why the other options are wrong:

  • A, 1: That is how far from the next multiple, not the remainder.
  • C, 5.83: That is ordinary division, with a decimal part.
  • D, 6: Close, but check your working: this is a small slip away from the answer.
  • E, 29: That subtracts once instead of dividing.

Sample question, level 4 of 5

What does this program output?

x ← 3
count ← 0
WHILE x < 58
  x ← x * 2
  count ← count + 1
ENDWHILE
OUTPUT count
  1. 5
  2. 6
  3. 4
  4. 19
  5. 96
Show the answer and method

Answer: A, 5

The method: x doubles until it is at least 58: it ends at 96 after 5 times round, so count is 5.

Why the other options are wrong:

  • B, 6: When x reaches 96 the condition x < 58 is false, so the loop stops.
  • C, 4: Check the last time round: x is still below 58 before the last doubling.
  • D, 19: The loop doubles x; it does not count up in steps.
  • E, 96: That is the final value of x, not count.

See where this fits: every GCSE option topic and Key Stage 3.

Related topics: Searching and sorting.