Acorn Computers BBC Micro Model B w/8271 — Acorn BBC Micro Model B w/8271 User Guide Manual PDF

52 9 More on variables In an earlier chapter the idea of ‘variables’ was introduced. Variables are a fundamental concept in computing, and it is not possible to go far without understanding them. As we have seen, it is possible to say LET X = 12 or just X = 12 and the computer knows that it must label a ‘box’ in its memory with the name X and that the current value of X is 12. With a variable it is possible to alter the value of what is in the box but not the name of the box itself. The statement X = 14 simply changes the value of X from 12 to 14. Similarly we can say X = X+1 which looks unusual – like an equation which does not balance.

In fact all that this is doing is saying to the computer – whatever the value inside your box X, increase it by 1 from now on. So far we have considered only numeric variables – that is, variables which contain numbers and on which arithmetic can be carried out. But the computer has letters and symbols of various kinds on its keyboard – what about them? Numbers and characters Although we can talk of the ‘number’ 22, we can also consider 22 as a pair of characters – in the same way as A, B, C, ?, $ are characters. In computing it is important to be able to distinguish between numbers and characters. Arithmetic can be carried out on numbers but not on characters.

To give you an example to show that this is not such an esoteric idea, consider 22. We can divide 22 by 2 and get 11 if 22 is taken to be a number. But if we talked about a train leaving ‘Platform 22’ the 22 here would be a pair of characters. You cannot, with a great deal of meaning, divide ‘Platform 22’ by 2 and get ‘Platform 11’. Next it’s important to have a look at the other major kind of variable used in computing – one which can hold characters, not numbers. This is called a string variable .