teach-ict.com logo

THE education site for computer science and ICT

2. One-dimensional arrays

Most programs will need to keep track of data. One way to do this is to store the data as independent variables.

Storing the names of players on a football team might look like this:

               SET player1 TO "John Smith"
               SET player2 TO "Simon Says"
               SET player3 TO "Jimmy Widget"
                 ... and so on
  

Once you have set up a variable to hold the names of each of the players, though, there is still no indication that there is a relationship between the names - i.e. that they are all part of the same football team.

This is where data structures come in. The simplest data structure is the array, which is simply a list of several pieces of data stored as a single variable.

All of the items within the array need to be the same type - you can't mix and match integers and strings, for example.

Declaring an array in pseudocode is as simple as:

               SET PlayerNames TO ["John Smith", "Simon Says", "Jimmy Widget"]

The square brackets mark the start and end of the list of items, and each item is separated by a comma.

 

Challenge see if you can find out one extra fact on this topic that we haven't already told you

Click on this link: What is an array