Using Arrays and Lists in Blitz
 

From the previous topic, about variables, you know how to store and manipulate different types of information. But what do you do when you need to store and manipulate data about many things which are all the same? Well, you could do this...
Code ; We want to store the exam marks of a class of students
result1.w=23
result2.w=97
result3.w=60
; And so on...
result99.w=78
result100.w=75
...but that would be a real hassle for getting your program to process the values, for actually programming it, and many other reasons (which I cannot think of right now :). Instead, you would use either arrays or lists, which are two different ways of storing large amounts of similar data.

An array is a block of memory which is capable of holding 'n' copies of a specific type of variable (you give the type and size of 'n' when you create the array). They are arranged linearly in memory (in Blitz) and items from the array are accessed by a so-called 'index' - this is the number of the item in the array you want to access (i.e. using an index of 0 will get you the first item in the array).

Lists are not arranged in the same way as arrays. Instead, each item in the list contains the type you define for the array and also some other control values. These allow you to move forwards and backwards through the list - you cannot access arbitary positions like with an array. However, lists are more dynamic than arrays, allowing you to add, remove and change the positions of items very quickly and easily in the middle of lists.

Both arrays and lists offer advantages and disadvantages, which will be discussed in the relevant parts of the fuller explanations of how to work with arrays and lists (the next two parts in this topic).


Previous Programming contents Next: Working with arrays


News | Introduction | Search | List/Forum/IRC Webring | Contact
Installation | Troubleshooting | Programming | Archives | Links
Return to programming main
Page last modified: 22nd August 2001