One Thing After Another
Give the computer several instructions and it does them in order. That order matters as much as the instructions do.
One instruction is a program. So is a list of them. Give the computer several instructions 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. That is all running a program is.
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. And now you are putting your shoes on before your socks.
The computer did not complain. It cannot. It has no idea what socks and shoes are, and it never checks whether an order makes sense. That part is your job.
Real programs go wrong the same way. Add up the score before you add the points, or draw the player before you move them, and the program does the wrong thing just as obediently.
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. Either it does not show anything, or it sits somewhere you did not mean to put it. Read the list again, in order.
What you’ve learnt
- A program is a sequence. The computer does each instruction in turn, from the top.
- The order is part of the program. The same instructions in a different order make a different program, and often a broken one.
- The computer never checks whether an order makes sense. Getting it right is your job.
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.