EXIT / ITERATE
Syntax
EXIT: EXIT FOR | WHILE | DO | FUNCTION | SUB
ITERATE: ITERATE FOR | WHILE | DO
Description
EXIT immediately terminates the specified loop or function. EXIT FOR, EXIT WHILE, and EXIT DO break out of their respective loops. EXIT FUNCTION and EXIT SUB perform an early return from a procedure, jumping directly to the epilogue.
ITERATE skips the remainder of the current loop iteration and jumps to the next condition check. For FOR loops, it jumps to the STEP increment and comparison. For WHILE and DO, it jumps directly to the condition test.
Parameters
| Parameter | Description |
FOR | Targets the innermost enclosing FOR/NEXT loop. |
WHILE | Targets the innermost enclosing WHILE/WEND loop. |
DO | Targets the innermost enclosing DO/LOOP. |
FUNCTION | EXIT only. Jumps to the function epilogue, returning the current FUNCTION = value. |
SUB | EXIT only. Jumps to the subroutine epilogue. |
Example
FUNCTION PBMAIN() AS LONG
LOCAL i AS LONG
' EXIT FOR: stop loop early
FOR i = 1 TO 100
PRINT "Checking: "; i
IF i = 5 THEN EXIT FOR
NEXT i
PRINT "Stopped at: "; i
' ITERATE FOR: skip even numbers
FOR i = 1 TO 10
IF (i AND 1) = 0 THEN ITERATE FOR
PRINT "Odd: "; i
NEXT i
' EXIT FUNCTION: early return
' IF someError THEN EXIT FUNCTION
FUNCTION = 0
END FUNCTION
EXIT
Syntax: EXIT FOR | EXIT WHILE | EXIT DO | EXIT FUNCTION | EXIT SUB
| Statement | Generated ASM | Jumps To |
| EXIT FOR | jmp __pb_for_end_N | Past NEXT |
| EXIT WHILE | jmp __pb_while_end_N | Past WEND |
| EXIT DO | jmp __pb_do_end_N | Past LOOP |
| EXIT FUNCTION | jmp __pb_routine_epilogue_N | Function epilogue |
| EXIT SUB | jmp __pb_routine_epilogue_N | Subroutine epilogue |
ITERATE
Syntax: ITERATE FOR | ITERATE WHILE | ITERATE DO
| Statement | Generated ASM | Jumps To |
| ITERATE FOR | jmp __pb_for_iter_N | STEP + condition check |
| ITERATE WHILE | jmp __pb_while_N | WHILE condition check |
| ITERATE DO | jmp __pb_do_iterate_N | LOOP condition check |
EXIT FUNCTION (Early Return)
; When EXIT FUNCTION is encountered:
jmp __pb_routine_epilogue_N ; skip to epilogue
; Epilogue (always at function end):
__pb_routine_epilogue_N:
mov rax, [rbp - return_offset] ; load FUNCTION = value
add rsp, frame_size
pop rbp
ret