This statement performs an unconditional branch and continues execution at a specified labeled instruction.
GoTo label
Prerequisites
None
Parameters
label
Required program instruction label. A label must conform to the naming conventions for either be a valid variable name (e.g. label3) or an integer literal (e.g. 1000).
Remarks
This instruction alters the sequence of program statement execution by setting the label’ed statement as the next instruction to be executed.
The referenced label’ed instruction must be in the same procedure as the GoTo instruction and can be on an instruction before or after the GoTo instruction. You should not use a GoTo to jump from the outside of a control structure (e.g. a For…Next or If…Then…Else…End If) to within a control structure.
To label an instruction, specify the label name followed by a colon (:) followed by any standard instruction.
In general, GoTo instructions can make code difficult to read and debug. So, wherever possible software should be written to make use of the other control structures, e.g. If…Then…Else…End If, While…End While.
Examples
Dim too_big As Boolean, angle As Single
too_big = False
angle = 175.5
If angle > 360 Or angle < -360 Then
too_big = True
GoTo Error_Exit ' An Else clause would be better,
End If ' but this shows how to use GoTo
my_routine(angle)
Error_Exit:
See Also
Statements |Do… Loop Statements| For…Next Statements | If…Then…Else…End If Statements | While…End While Statements