GOTO labelPB_STMT_GOTO handler (pb_codegen.c:6625)Transfers execution unconditionally to a specified label within the same function or subroutine. GOTO is commonly used for error handling, cleanup code, and skipping sections of code. Labels are defined by an identifier followed by a colon. The compiler generates a direct jmp instruction to the label's address.
| Parameter | Description |
|---|---|
label | The name of the target label (without the trailing colon). The label must be defined in the same FUNCTION or SUB. |
FUNCTION PBMAIN() AS LONG
LOCAL x AS LONG
x = -5
' Error handling with GOTO
IF x < 0 THEN GOTO ErrorHandler
PRINT "Value is OK: "; x
GOTO Cleanup
ErrorHandler:
PRINT "Error: negative value detected!"
x = 0
Cleanup:
PRINT "Finished with x = "; x
FUNCTION = 0
END FUNCTION
; Direct GOTO: jmp __pb_label_<routine>_<labelname> ; Label definition: __pb_label_<routine>_<labelname>:
IF x < 0 THEN GOTO ErrorHandler PRINT "OK" GOTO Done ErrorHandler: PRINT "Error!" Done: PRINT "Finished"
; Generated assembly: mov rax, [rbp - x_offset] cmp rax, 0 jge __pb_skip_N ; skip if x >= 0 jmp __pb_label_PBMAIN_ErrorHandler __pb_skip_N: ; PRINT "OK" code jmp __pb_label_PBMAIN_Done __pb_label_PBMAIN_ErrorHandler: ; PRINT "Error!" code __pb_label_PBMAIN_Done: ; PRINT "Finished" code