Next: Parameters
Up: Subroutines
Previous: Subroutines

Using Subroutines

If you take a look at ``subroutine.f'' in your ``examples'' directory (or view it directly), you will see an example of the definition and use of a subroutine. Take a look at it, and run it, and then we'll discuss it.

Look first at the main program. How does the way we call the subroutine ``FIVE'' differ from the way we call functions?

Click here for the answer

Now look at the definition of FIVE. How does it differ from a FUNCTION definition?

Click here for the answer

As you can see, there are many more similarities between functions and subroutines than there are differences. The differences stem from the fact that functions return values and subroutines cause side effects. In the case of our example, what is the side effect?

Click here for the answer

Printing is just one possible side effect. In the next section, we'll look at a different kind of side effect.


Next: Parameters
Up: Subroutines
Previous: Subroutines

Hamlet Project
hamlet@cs.utah.edu