B2.3.1 · Programming constructs
Sequence and state
By the end you can
Trace sequential execution and compound assignment operations tracking variable state mutations.
The most fundamental programming construct is : instructions execute strictly one after another from top to bottom, unless diverted by selection, iteration, or subroutine calls.
State and mutation#
The of a program consists of the values stored in all variables and memory locations at any given moment. Every sequential assignment statement (e.g. counter = counter + 1) mutates the state by replacing old values in memory with new evaluated expressions.
In tracing sequential execution, order is paramount. Swapping the order of two assignment lines can completely change the resulting state of the system or trigger unintended bugs.
Check yourself
Sequence and program state
Quick questions, made fresh every time and marked here. Do a few until they feel easy.
Exam practice
Paper 1-style questions
3 questions · 9 marks
Write your answer as you would in the exam, then show the mark points and tick each one your answer made. These are our own questions in the style of the exam, not past-paper questions.
1.Trace the values of variables x and y after the following sequential instructions: x = 5; y = 10; x = x + y; y = x - y; x = x - y.
[3]Trace: Follow the program or process step by step, recording the values.
2.Explain what is meant by the 'state' of a program during sequential execution.
[2]Explain: Give reasons: say what happens AND why, or how one thing causes another.
3.Construct a sequence of statements in pseudocode that swaps the values of two variables a and b using a temporary variable temp, and describe the state after each step.
[4]Construct: Draw or write it out (a table, a diagram, a program).
In a nutshell
- Sequence executes instructions strictly one after another from top to bottom.
- Program state represents the snapshot of all variable values and memory contents at a given instant.
- Assignment statements mutate state chronologically, making statement ordering critical for deterministic results.
- Trace tables track state mutations row by row to verify intermediate variable invariants.
