Skip to content
S3U
Login Create Account

Science / Programming basics / Grade 3 / sc370

Programming Basics: Track a Variable

Keep a record of a value as instructions change it.

All worksheets
5 questions0m 0s

Learn first

Programs follow precise instructions

A program is a set of instructions. A variable stores a value. A condition chooses between paths. A loop repeats steps. Output is the result produced.

How to work it out Trace one instruction at a time. Keep a record of values and check exactly when a condition or repeated step is evaluated.

A separate example In a separate trace, start with n = 2, add 3, then double n. The two instructions happen in order: 5 is an intermediate value before the final result.

Learn the skill

These sheets use pseudocode: readable instructions, not a particular programming language. SET score TO 2 gives score the value 2. SET score TO score + 3 reads the old value first, then replaces it. SHOW displays the current value without changing it.

Worked example

Trace SET score TO 2; SET score TO score + 3; SHOW score. The values are 2 then 5, and the display shows 5. A variable is a name for a value, not the printed word itself.

SET score TO 2 stores two. SET score TO score + 3 reads two and stores five. SHOW score displays five without changing the stored value.
SET score TO 2 stores two. SET score TO score + 3 reads two and stores five. SHOW score displays five without changing the stored value.
Question 1 What is score after SET score TO 2?
Question 2 What is score after the next instruction adds 3?
Question 3 What does SHOW score display at the end?
Question 4 If the next instruction is SET score TO 1, what is score now?
Question 5 Does SHOW score change score in this pseudocode?