20 4 A simple program In the previous chapter we have been giving the computer commands which it obeys immediately. The problem with this technique is that you have to wait until the computer has completed one command before you can give it the next one. If the computer takes a long time to work out one of the problems you have set it, then you may have to waste an awful lot of time just sitting there waiting for it. For example if you want your computer to work out the number of Ј1, Ј5 and Ј10 notes that you will need to pay the wages at the end of the week the computer will take a fair time to calculate all the wages before it can sort out the notes required.
The same problem comes up when you take a car into a garage to be serviced. You could for example stand by the mechanic and say ‘First of all I want the oil changed’ and then you could wait for him to change the oil. When that is completed you could then say ‘Now I want you to replace the bulb that has blown in one of the front headlights’ and then you could wait for that job to be done. And thirdly you might say ‘The exhaust is making a noise, so I want you to put the car up on the ramp and check it’. You would spend a great deal of time waiting for the mechanic to complete each job before assigning the next.
There is a far more efficient way of doing things; when you go into the garage you give the mechanic a whole set of instructions, for example: – First of all change the oil. – Secondly replace the headlight bulb. – Thirdly stop the noise in the exhaust. Once you have given your set of instructions and checked that the garage understands what has to be done, you can walk off and have a cup of coffee and then go back expecting the job to be finished. Now the same thing applies with a computer. It is far better to give it a whole set of instructions and let it run while you wander off and have a cup of coffee. ‘Writing a computer program’ is nothing more than giving a set of instructions.
If you give the computer a command like PRINT "HOW ARE YOU" then the computer will do that immediately. On the other hand, if you give the computer a statement 10 PRINT "HOW ARE YOU"