Traversing a 1-D Array

To traverse an array means to access each element (item) stored in the array so that the data can be checked or used as part of a process.

In most high-level languages, it is necessary to create a variable that will track the position of the element currently being accessed. This variable is often referred to as a loop counter.

When used in high-level languages, the name given to the loop counter is usually ‘i’ or ‘counter’.

Traversing an array within upper and lower bounds

If a loop is set to repeat ten times (from 0 to 9) then:

  • during the first iteration the loop counter will hold the value 0
  • during the second iteration it will hold 1
  • during the third iteration it will hold 2 and so on

This lets the program access the elements stored in the array in order

Python Code Example

The output for the above program would be:

9.87
8.76
9.65