



RETURN Statement RETURN statement just consists of the keyword
RETURN
Its effect is to stop the procedure executing and to return control, and
where appropriate argument and function values, to the calling program unit.
The execution of the END statement at the end of the program unit has
the exactly the same effect, so that RETURN is superfluous in procedures
which have only one entry and one exit point (as all well-designed procedures
should). It is, however, sometimes convenient to use RETURN for an emergency
exit. Here is a somewhat simple-minded example just to illustrate the point:
REAL FUNCTION HYPOT(X, Y) *Computes the hypotenuse of a right-angled triangle. REAL X, Y IF(X .LE. 0.0 .OR. Y .LE. 0.0) THEN WRITE(UNIT=*,FMT=*)'Warning: impossible values' HYPOT = 0.0 RETURN END IF HYPOT = SQRT(X**2 + Y**2) END |
X = HYPOT(12.0, 5.0) Y = HYPOT(0.0, 5.0) |
In the external function shown above it would have been perfectly possible to avoid having two exits points by an alternative ending to the procedure, such as:
IF(X .LE. 0.0 .OR. Y .LE. 0.0) THEN WRITE(UNIT=*,FMT=*)'Warning: impossible values' HYPOT = 0.0 ELSE HYPOT = SQRT(X**2 + Y**2) END IF END |
RETURN statement were to be used than with almost all of the procedure
contained within an ELSE-block. A third possibility for emergency exits is to use
an unconditional GO TO statement to jump to a label placed on the END
statement.