We are now ready for the program that reverses the order of a list of
names. Here the array index is an integer variable
! Reverse the order of a list of names
, "Enter 50 names in quotes, one to a line"
! Read list of names
j = 1, 50
, "Here is reversed list"
! Output reversed list
i = 50, 1, -1
The data input is a list of 50 names, each in quotes, one to a line.
Now, perhaps, you can see what a powerful programming tool the
indexed variable can be. In the
loops the index
that is counting the
loops can be used to refer to the different members of the list. In the first
loop the names are read; the first is stored in the variable
the second in
and so on.
In contrast, we want the output
loop to output
, and so on. We use a
negative step size.
When an array such as
is being read into the computer we do
not need to write out a do loop; we can use a shorter form in which a
loop is implied. Instead of writing
do i = 1, 50
we can write the single statement