102 21 Even more on variables Arrays Very often we use the computer to store and manipulate sets of data rather than just a single value. For example, we might want to calculate wages for a group of people or sort a group of 20 numbers into order. The 20 numbers might well be associated with 20 names. Arrays make it a lot easier to deal with groups of names and numbers. To get to a more manageable example let’s consider working with five names and their associated year of birth. We could store the five names in five variables like this: N1$ = "SARDESON" N2$ = "MATTINSON" N3$ = "MOIR" N4$ = "ALLEN" N5$ = "MOUNT" That is quite reasonable and it works.
If you say PRINT N2$ the computer will then print out MATTINSON . However, you cannot tell it to print out the fifth entry or the fourth entry. The computer doesn’t have any way of knowing that is the fifth entry. Using arrays, though, we can pick out the fifth entry in a long list and that is very useful. The first thing we have to do is to tell the computer how large an array we are going to use. This is done with a DIM statement – eg DIM N$(5) creates an array (a table) and we can then say N$(1) = "SARDESON" N$(2) = "MATTINSON" N$(3) = "MOIR" N$(4) = "ALLEN" N$(5) = "MOUNT" If we follow that with X = 1 and then say