RETURN

Purpose

The RETURN statement:
  • In a function subprogram, ends the execution of the subprogram and returns control to the referencing statement. The value of the function is available to the referencing procedure.
  • In a subroutine subprogram, ends the subprogram and transfers control to the first executable statement after the procedure reference or to an alternate return point, if one is specified.
  • In the main program, ends execution of the executable program.

Syntax

Read syntax diagramSkip visual syntax diagram
>>-RETURN--+----------------+----------------------------------><
           |            (1) |   
           '-arith_expr-----'   

Notes:
  1. Real or complex expressions are an IBM extension.
arith_expr
A scalar integer, real, or complex expression. If the value of the expression is noninteger, it is converted to INTEGER(4) before use. arith_expr must not be a Hollerith constant.

Rules

arith_expr can be specified in a subroutine subprogram only, and it specifies an alternate return point. Letting m be the value of arith_expr, if 1 ≤ m ≤ the number of asterisks in the SUBROUTINE or ENTRY statement, the mth asterisk in the dummy argument list is selected. Control then returns to the invoking procedure at the statement whose statement label is specified as the mth alternate return specifier in the CALL statement. For example, if the value of m is 5, control returns to the statement whose statement label is specified as the fifth alternate return specifier in the CALL statement.

If arith_expr is omitted or if its value (m) is not in the range 1 through the number of asterisks in the SUBROUTINE or ENTRY statement, a normal return is executed. Control returns to the invoking procedure at the statement following the CALL statement.

Executing a RETURN statement terminates the association between the dummy arguments of the subprogram and the actual arguments supplied to that instance of the subprogram. All entities local to the subprogram become undefined, except as noted under Events causing undefinition.

A subprogram can contain more than one RETURN statement, but it does not require one. An END statement in a function or subroutine subprogram has the same effect as a RETURN statement.

Examples

CALL SUB(A,B)
CONTAINS
  SUBROUTINE SUB(A,B)
    INTEGER :: A,B
    IF (A.LT.B)
      RETURN            ! Control returns to the calling procedure
    ELSE
      ...
    END IF
  END SUBROUTINE
END
 

Related information



Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us