Home > Language Reference > Program Flow Functions > GoTo

GoTo

The GoTo function branches unconditionally to a line specified by a label within the script.

Usage

Even if Goto is an easy way to make a jump to another section of the script, it makes scripts unreadable and difficult to debug. Use instead Sub to call a sub-program which executes the section you want.

Syntax

GoTo <label>

Parameters

<label>, constant, label of the line where to jump.
The syntax of the line where to jump is:
<label>:
Note the : just after the label identifier.

Compilation detects undefined labels or same label used in multiple GoTo.

Examples

next:
    ret=msgbox("Would you like to continue ?",4,"EXAMPLE")
    If ret=7 then
        stop
    endif
    'The loop is repeated until "No" button is clicked in the message box
GoTo next

  
'Replace the goto by a better structure using Sub
Sub continue()
    ret=msgbox("Would you like to continue ?",4,"EXAMPLE")
EndSub

'Call the Sub when it is needed within the script
  ret=0
  While ret<>7
      continue()
  Wend