Arrays and DO loops



By this time, you should be familiar with the concepts of variables. As you know, variables are little pieces of memory, at a certain memory location, that hold a value, and are tied to a name and a type.

In the example below, click on the words "Name", "Value" or "Type" to see what part of the variable it affects.



In contrast to single variables, arrays can be thought of as a group of homogeneous variables all tied together under a common name and in a distinct memory location. However, the computer can only access one of these areas at a time, so each cell must have a specific name. This is done through indexing. Indexing means giving a special number within brackets to each cell.

The example below is meant to represent and array. Click in the same row as the words "Name", "Value" and "Type" and within the individual array element to see the parts represented.


Because of the computers desire to chose a specific element of an array using a number, the most natural way to enter data into an array is by using a loop, such as DO or DO-WHILE. Below is a short program showing how an array can be accessed and changed using loops or direct access. As in the other examples, each variable changes as the line of the code is executed.