RETURN


ANSI

 

The RETURN instruction terminates a subroutine, returning program control to the top element of the subroutine call stack (LIFO - Last In First Out). The instruction uses the following formats:

 

(1)

[label]

RETURN

 

(2)

[label]

RETURN

IF [NOT] {flag}

(3)

[label]

RETURN

IF [NOT] {expression}

(4)

[label]

RETURN

[USING {retvar} ][IF [NOT] {expression}]

 

Where:

label

Optional. A Program Execution Label.

flag

Required. One of the condition, pseudo condition or function Flags that determines whether the RETURN will occur.

expression

Required. An Expression that, if true, causes the program to RETURN to the location on the top of the call stack.

retvar

Optional. A DIM, FORM, INTEGER, CONST, Numeric Expression, or GUI Object that is returned to a CALL GIVING variable.

Flags Affected: Function Key

Note the following:

  1. Function Flags (Function keys) are cleared if tested and found TRUE. All other Flags remain unchanged.

  2. If a FILEPI instruction is active, the FILEPI count is not decremented by this instruction.

  3. Format (3) terminates the subroutine only if {expression} evaluates to a true condition. Otherwise, execution continues with the next sequential instruction.

  4. The optional USING syntax format (4) is only supported within the (L)FUNCTION scope. If the {retvar} is a DIM, FORM, or INTEGER variable or pointer, the {retvar} is normally moved to the CALL GIVING variable by value. However, if the CALL GIVING variable is a pointer that has a NULL pointer address, the following behaviors occurs:

  5.  

    a. If the CALL GIVING is a pointer variable that has a NULL pointer address and the RETURN {retvar} is normal DIM, FORM, INTEGER variable (not pointer), the RETURN operation is ignored and no move action is performed.

     

    b. If the CALL GIVING is a pointer variable that has a NULL pointer address and the RETURN {retvar} is DIM, FORM, INTEGER pointer variable outside the scope of the (L)FUNCTION, the RETURN {retvar} pointer address is assigned to the CALL GIVING pointer variable. However, if the RETURN {retvar} pointer address points to a local variable within the (L)FUNCTION scope, the RETURN {retvar} move action is ignored.

     

    c. If a (L)FUNCTION is called using a PLBOBJECT method with GIVING using a DIM, FORM, or INTEGER NULL pointer variable, the RETURN behaviors using format (4) are the same as described for 'CALL GIVING' variables in Note (4.).

 

 

See Also: Example Code, CALL, RETCOUNT, NORETURN, Program Control Instructions

 



PL/B Language Reference RETCOUNT ROUTINE