Search code examples
functionfortranreturnsubroutinefortran95

Is Fortran return statement obsolete?


I just want to know if the return statement in Fortran 2008 is obsolete, because it seems to be unnecessary to write it at the end of subroutines and functions.

Does it have some other utility?


Solution

  • No, it is not obsolete.

    It is used to exit a subroutine and a function. Whenever you want to exit in the middle of a subroutine, you use RETURN. For example, when some error happens or similar.

    Using RETURN is an alternative to long IF conditions like:

    if (no_error) then
         [...a lot of code...]
    end if
    

    Instead you just do:

     if (error) return
     [...a lot of code...]