Next: DO Loop Syntax
Up: DO Loop Basics
Previous: Why DO Loops?

The Power of Looping

In the example that you just saw, we used a DO loop to repeat its body a fixed number of times. It is important to realize that the number of repetitions can be controlled by a variable. How could you modify ``loop3.f'' so that the user could specify the number of numbers that should be subsequently read and summed?

Click here for the answer

Take a look at ``loop4.f'' (or view it directly) for an example of this idea in action. Notice that we read the number ``N'' from the user, and then use this variable to control the number of repetitions.

Now you can begin to appreciate the true power of DO loops. In the last section, we simply used a DO loop to shorten a program. Here, we used a DO loop to do something that could not otherwise be done. We can repeat a segment of code any number of times!


Next: DO Loop Syntax
Up: DO Loop Basics
Previous: Why DO Loops?

Hamlet Project
hamlet@cs.utah.edu