Skip to content
MathAnvil
§ Coding

Sequences & Instructions

§ Coding

Sequences & Instructions

LK20.103 min read

A sequence in coding refers to a set of instructions executed one after another in a specific order. The order of operations determines the final outcome, making sequential thinking fundamental to programming and computational problem-solving. Variables store values that can be updated through each step of the sequence.

§ 01

Why it matters

Sequential thinking appears throughout GCSE Computer Science and forms the foundation for programming algorithms. Traffic light systems follow sequences to manage intersections safely, with each light changing in a predetermined order over 90-second cycles. Banking software processes transactions sequentially to maintain accurate account balances, ensuring a £50 deposit followed by a £30 withdrawal results in the correct final amount. Video game mechanics rely on sequences for character movement, where pressing arrow keys in different orders produces different on-screen results. Manufacturing robots follow sequential instructions to assemble products, with each step building upon the previous one. This logical reasoning transfers to mathematical sequences, algebraic problem-solving, and data analysis skills essential for A-level Mathematics and beyond.

§ 02

How to solve sequences & instructions

Sequences in Code

  • A sequence is a set of instructions executed one after another.
  • Order matters: changing the order changes the result.
  • Variables store values that can be updated.
  • Trace through the code line by line to find the output.

Example: x = 3, x = x + 2, print(x) → outputs 5.

§ 03

Worked examples

Beginner§ 01

You climb stairs: start at step 0, go up 3 steps at a time, 3 times. Which step?

Answer: 9

  1. Execute each step 0 -> 3 -> 6 -> 9 Go up 3 steps each time.
  2. Final value 9 After 3 additions of 3: 0 + 3 x 3 = 9.
Easy§ 02

A rumour spreads: 1 person tells 2, each tells 2 more. After 3 rounds, how many know?

Answer: 8

  1. Double each round 1 -> 2 -> 4 -> 8 The number doubles each round.
Medium§ 03

A loop repeats 'add 5' 4 times starting from 1. Final value?

Answer: 21

  1. Trace the loop 1 -> 6 -> 11 -> 16 -> 21 Each iteration adds 5.
  2. Or calculate directly 1 + 5 x 4 = 21 Start + (step x repeats).
§ 04

Common mistakes

  • Executing steps out of order produces incorrect results. For example, starting with x = 5, then x = x × 2, then x = x + 3 gives 13, but reversing the last two operations gives 16 instead of 13.
  • Forgetting to track variable updates leads to errors. If x starts at 2, then x = x + 4, then x = x × 3, the final value is 18, not 14 (which incorrectly uses the original value of 2).
  • Miscounting loop iterations changes the outcome. A loop adding 3 starting from 0 for 4 iterations reaches 12, not 9 (which assumes only 3 iterations).
§ 05

Frequently asked questions

What is the difference between a sequence and a loop in coding?
A sequence executes each instruction once in order, whilst a loop repeats the same instruction multiple times. A sequence might be x = 5, x = x + 2, x = x × 3, giving one result. A loop repeats x = x + 2 several times, producing different outcomes based on iteration count.
How do you trace through code with variables?
Follow each line step by step, updating variable values as you go. Write down the variable's value after each instruction. For x = 3, x = x × 2, x = x + 1, trace: x starts as 3, becomes 6 after multiplication, then becomes 7 after addition.
Why does order matter in sequences?
Different orders produce different results because each step uses the current variable value. Starting with x = 10, doing x = x ÷ 2 then x = x + 5 gives 10, but reversing to x = x + 5 then x = x ÷ 2 gives 7.5.
What happens if you skip a step in a sequence?
Skipping steps changes the final outcome entirely. In a sequence x = 4, x = x × 3, x = x - 2, skipping the middle step means x goes from 4 directly to 2, instead of the correct path: 4 to 12 to 10.
How do you check if your sequence answer is correct?
Re-trace through each step carefully, writing down intermediate values. Alternatively, work backwards from known patterns. For repeated addition starting at 0, use start + (step × repetitions). For doubling sequences starting at 1, use initial × (factor^repetitions).
§ 06

See also

§ 06

Related topics

Share this article