GOTO statement

Language reference ›› Statements ››
Parent Previous Next

PMP supports program label and branch statements:


label-item-declaration = label-item ":" .
goto-statement = GOTO label-item .
label-item = identifier .


<label-item> must conform to the standard identifier format.



<label-item> is local to the current procedure, function, main program or unit initialization block, so a GOTO cannot jump outside of the current scope.


Forward label references are allowed in a PMP program.


PMP labels translate to an internal representation as for any identifier (prefixed with module name and procedure or function name).


[Spaghetti code]


FOR I := 1 TO 10 DO
 BEGIN
   … // Do Something
   IF A THEN GOTO Label_A;
   … // Something not executed if A = TRUE
   GOTO Label_B;
   Label_A:
   … // Something executed if A = TRUE
   Label_B:
 END;



[Bad code]


IF A THEN GOTO Label_A;
FOR I := 1 TO 10 DO
 BEGIN
   … // Do Something
   Label_A:
   … // Do Something else
 END;

Well, everybody would say that this is not a good practice (indeed), but PMP will not flag it…