HP Fortran Programmer's Reference (September 2007)

HP Fortran statements
FUNCTION
Chapter 10364
As noted above, a recursive function that calls itself directly must have the
RESULT clause specified. For other functions, the RESULT clause is optional.
Description
A FUNCTION statement introduces an external, module, or internal function subprogram.
Examples
PROGRAM main
...
CONTAINS
! f is an internal function
FUNCTION f(x)
f = 2*x + 3
END FUNCTION f
! recursive function, which must specify RESULT clause
RECURSIVE INTEGER FUNCTION factorial (n) &
RESULT (factorial_value)
IMPLICIT INTEGER (a-z)
IF (n <= 0) THEN
factorial_value = 1
ELSE
factorial_value = n * factorial (n-1)
END IF
END FUNCTION factorial
END PROGRAM main
Related statements
CONTAINS, END, INTENT, INTERFACE, OPTIONAL, and the type declaration statements
Related concepts
For related information, see the following:
“Type declaration for intrinsic types” on page 109
“External procedures” on page 161
Arguments” on page 171
“Defined operators” on page 185