Iterating over elements in a variety of built-in data structures. Let’s see how to use loops with some of the data structures we’ve already learned.
Here we use a loop to sum the numbers in an array. Arrays work like this too.
Loop on arrays provides both the index and value for each entry. Above we didn’t need the index, so we didn’t use it explicitly. Sometimes we actually want the indexes though.
Loop on arrays iterates over key-value pairs.
A loop can also iterate over just the keys of an array.
Loop on strings iterates over characters. The first value is the starting byte index of the character and the second the character itself.
To run the program, you can use a Fortran compiler like gfortran.