IB Statements/pop

From CometWiki

Jump to: navigation, search

POP statement

Syntax: POP

Discussion: The POP statement clears the most recent return address from the subroutine stack. It is used to exit from a subroutine with a control transfer statement other than RETURN (e.g., a GOTO statement), or perform a direct return to the main program from a nested subroutine.

Note: If the subroutine stack is empty, the POP statement has no effect (i.e, it does not result in an exception branch).

Also see POPALL.

Example 1:

 GOSUB 1000
 .
 500     PRINT (0) "CUSTOMER OVER CREDIT LIMIT."
       .
 1000    OPEN (1) "C1A", EXCP=9000
       READ (1,1000) EXCP=8000
       .
       IF ARTOTAL > CRLIMIT THEN POP & GOTO 500
       .
       RETURN

In the above example, the main section of the program directs control to subroutine label 1000. In that subroutine, if a certain condition is met (namely ARTOTAL greater than CREDIT limit), the most recent entry in the subroutine stack is popped and program control is transferred directly to statement 500 in the main section.

Example 2:

 GOSUB 1000
 .
 500     PRINT (0) "CUSTOMER OVER CREDIT LIMIT."
 .
 1000    OPEN (1) "C1A",EXCP=9000
       READ (1,1000) EXCP=8000
       IF ARTOTAL > 0 THEN  2000
 1100    PRINT (0) "CUSTOMER INFORMATION:"
       .
       RETURN
 2000    FLAG1$ = "Y"
       IF ARTOTAL > CRLIMIT THEN POP & POP & GOTO 500
       .
       RETURN

In this example, the main section of the program directs control to subroutine label 1000. Within that subroutine, if a certain condition is met (namely if ARTOTAL is greater than 0), program control is directed to a nested subroutine at label 2000.

Within the nested subroutine, if a certain condition is met (in this case, ARTOTAL greater than CRLIMIT), the two most recent return addresses are popped from the subroutine stack, and program control is transferred directly to statement 500 in the main section.

Personal tools