### 8.5.2.1 RESULT Keyword

Normally, a function result is returned in the function's name, and all references to the function name are references to the function result.

However, if you use the RESULT keyword in a FUNCTION statement, you can specify a local variable name for the function result. In this case, all references to the function name are recursive calls, and the function name must not appear in specification statements.

The RESULT name must be different from the name of the function.

The following shows an example of a recursive function specifying a RESULT variable:

    RECURSIVE FUNCTION FACTORIAL(P) RESULT(L)
      INTEGER, INTENT(IN) :: P
      INTEGER L
      IF (P == 1) THEN
        L = 1
      ELSE
        L = P * FACTORIAL(P - 1)
      END IF
    END FUNCTION

Previous Page Next Page Table of Contents