13.1.3 Goto statements

Free Pascal supports the goto jump statement. Its prototype syntax is

_________________________________________________________________________________________________________
Goto statement

--            -     -    ----------------------------------------
  goto statement goto label
___________________________________________________________________

When using goto statements, the following must be kept in mind:

  1. The jump label must be defined in the same block as the Goto statement.
  2. Jumping from outside a loop to the inside of a loop or vice versa can have strange effects.
  3. To be able to use the Goto statement, the -Sg compiler switch must be used, or {$GOTO ON} must be used.

Remark: In iso or macpas mode, or with the modeswitch ”nonlocalgoto”, the compiler will also allow non-local gotos.

Goto statements are considered bad practice and should be avoided as much as possible. It is always possible to replace a goto statement by a construction that doesn’t need a goto, although this construction may not be as clear as a goto statement. For instance, the following is an allowed goto statement:

label  
  jumpto;  
...  
Jumpto :  
  Statement;  
...  
Goto jumpto;  
...