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?
Now look at the definition of FIVE. How does it differ from a FUNCTION definition?
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?
Printing is just one possible side effect. In the next section, we'll look at a different kind of side effect.
Hamlet Project