TAL Reference Manual
Statements
TAL Reference Manual—526371-001
12-33
Examples of RETURN Statements
Examples of RETURN Statements
1. This function contains two RETURN statements nested in an IF statement:
INT PROC other (nuff, more); !Declare function with
! return type INT
INT nuff;
INT more;
BEGIN
IF nuff < more THEN !IF statement
RETURN nuff * more !Return a value
ELSE
RETURN 0; !Return a different value
END;
2. This procedure returns control to the caller when A is less than B:
PROC something;
BEGIN
INT a,
b;
!Manipulate A and B
IF a < b THEN
RETURN; !Return to caller
!Lots more code
END;
3. This function returns a value and a condition code to inform its caller that the
returned value is less than, equal to, or greater than some maximum value:
INT PROC p (i);
INT i;
BEGIN
RETURN i, i - max_val; !Return a value and a
END; ! condition code
4. This procedure returns a condition code that indicates whether an add operation
overflows:
PROC p (s, x, y);
INT .s, x, y;
BEGIN
INT cc_result;
INT i;
i := x + y;
IF $OVERFLOW THEN cc_result := 1
ELSE cc_result := 0;
s := i;
RETURN , cc_result; !If overflow, condition code
END; ! is >; otherwise, it is =