One instruction is a program. So is a list of them. Give the computer several instructions in these examples and it does them in order, from the top.
That order matters as much as the instructions do.
In order, from the top
Here are three instructions:
SHOW "Put your socks on"
SHOW "Put your shoes on"
SHOW "Go outside"Run it, and the three lines appear in the order you wrote them:
Put your socks on Put your shoes on Go outside
The computer started at the top and worked down, one instruction at a time. These lines display advice; they do not dress anyone or move them outside.
The order is the program
Now swap the first two lines around:
SHOW "Put your shoes on"
SHOW "Put your socks on"
SHOW "Go outside"Put your shoes on Put your socks on Go outside
Those are the same three instructions. Only their order changed. The displayed advice now puts shoes before socks.
Each SHOW is valid in our notation, so this sequence has no instruction error to report. It still gives advice in an order we did not intend. We must compare the output with the purpose of the program.
Real programs go wrong the same way. Add up the score before you add the points, or draw the player before moving them when we wanted the new position, and the result can differ from our intention.
If we swap the first two SHOW lines, does Go outside move to the first output line?
Show the explanation
No. The third instruction stays third. The first two output lines swap, and Go outside remains last. All three outputs are text, not physical actions.
When it’s wrong, see why
- The lines come out in an order you did not expect. Read your program from the top. The order you read is the order it runs.
- A line never appears. Check that you ran the intended version and reached that line. A run may have stopped, or earlier output may have scrolled away. Compare the first unexpected observation rather than assuming the line vanished.
What you’ve learnt
- These examples are sequences, followed one instruction at a time.
- The order is part of the program. The same instructions in a different order make a different program, and often a broken one.
- Valid instructions can still produce an unintended order; check their result.
What’s next
So far the computer only shows words you typed yourself. In Unit 3 it starts showing values it works out, which is the first step from a program that recites to one that does something.