TAL Programmer's Guide

RETURN Statement
Controlling Program Flow
096254 Tandem Computers Incorporated 12–21
RETURN Statement The RETURN statement returns control to the caller. If the invoked procedure or
subprocedure is a function, RETURN must return a result. As of the D20 release,
RETURN can also return a program-specified condition code (CC).
The form of the RETURN statement depends on whether the return is from a function
or from a procedure or subprocedure that is not a function.
Returning From Functions A function should contain a RETURN statement and must return a result-expression to
the caller. The result-expression can be any arithmetic or conditional expression of the
same data type as specified in the function declaration. (A function can be a procedure
or a subprocedure.)
If a function lacks a RETURN statement, the compiler issues a warning but the
compilation can complete and the resulting object file can be run. After the function
executes, it returns a zero.
The following function returns the result-expression 20 in a RETURN statement:
INT PROC a;
BEGIN
!Lots of code
RETURN 20; !Return a result from a function
END;
The following function contains two RETURN statements nested in an IF statement:
INT PROC other (nuff, more); !Declare function with type INT
INT nuff;
INT more;
BEGIN
IF nuff < more THEN !IF statement
RETURN nuff * more !Return either of two
ELSE ! results based on the
RETURN 0; ! condition NUFF < MORE
END;