In the last two examples of looping, the value of the loop variable was not used inside of the loop. That is, even though the value of ``I'' was counting up from 1 to ``N'', the particular value each time through the loop was not used. All that we cared about was that the loop ran through N iterations.
It is very common to make use of the value of the loop variable inside of the loop. For example, suppose that we'd like to write a program to compute the sum of the squares of the numbers from 1 up to 5. Take a look at ``loop5.f'' in your ``examples'' directory (or view it directly) for a program that does this. Notice that we repeat the same pattern five times, but not exactly the same statement. What changes about the pattern each time?
If we want to succeed in coding this sequence of statements as a loop, we must find a way to make each instance of the pattern identical. We can do this by letting the value to be squared in each statement be a variable. Think about this for a bit, and then look at ``loop6.f'' (or view it directly). What have we done to ensure that five identical pairs of sequences are executed?
Now we've got the program into a form in which we can exploit a DO loop. See if you can figure out how to do that before looking at my solution in ``loop7.f'' (or view it directly).
Notice that we can take out the statement that initializes ``I'' to 1, as well as all of the statements that add one to I/@. Why is that?
Now it should be a simple matter to modify the program so that it computes the sum of the squares from 1 up to 10. See if you can do that yourself.
Hamlet Project