pTAL Reference Manual (H06.08+)

Statements
HP pTAL Reference Manual523746-006
12-36
Procedures and Subprocedures
Procedures and Subprocedures
In procedures and subprocedures that are not functions, a RETURN statement is
optional. A nonfunction procedure or subprocedure that returns a condition code value,
however, must return to the caller by executing a RETURN statement that includes
cc-expression.
In a procedure designated MAIN, a RETURN statement stops execution of the
procedure and passes control to the operating system.
Procedures that return a condition code must specify explicitly the value of the
condition code to return to the procedures caller. In general, a procedure or
subprocedure returns control to the caller when:
A RETURN statement is executed.
The called procedure or subprocedure reaches the end of its code.
The procedure in Example 12-36 on page 12-37 returns a condition code that indicates
whether an add operation overflows.
INT PROC p2 (i);
INT i;
BEGIN
INT j := i + 1;
RETURN i, j;
END;
CALL p1 (i);
IF < THEN ... ; ! Test return value
CALL p2 (i);
IF < THEN ... ; ! Test condition code
Example 12-35. RETURN Statement in a Procedure
PROC something;
BEGIN
INT a,
b;
! Manipulate a and b
IF a < b THEN
RETURN; ! Return to caller
! Lots more code
END;
Example 12-34. Testing a Condition Code (page 2 of 2)