RECURSIVE attribute

Standard: F77 F90 F95 F2003 F2008 F2018 Example program



The RECURSIVE keyword may appear only in the prefix of a FUNCTION or SUBROUTINE statement.


The RECURSIVE keyword specifies that all procedures defined by this subprogram may be called recursively. (A subprogram can define several procedures by using the ENTRY statement.)

Note that in the case of a function, direct recursion is only possible if the RESULT clause is also used, as otherwise the function name is taken to mean the result variable name.

Prior to Fortran 2018, an elemental procedure was not permitted to have this attribute.

From Fortran 2018, all procedures, except for CHARACTER(*) functions, have this attribute by default, and thus may be called recursively. This includes elemental procedures. The NON_RECURSIVE attribute may be used to specify that a procedure will not be called recursively.


ELEMENTAL attribute, ENTRY statement, FUNCTION statement, NON_RECURSIVE attribute, RESULT clause, SUBROUTINE statement