GoTo statement transfers control unconditionally to a specified line in a procedure.
GoTo statement can branch only to lines in the procedure in which it appears.
GoTo can refer to.
The basic syntax of the
GoTo statement looks like as shown below.
Place an identifier, followed by a colon, at the beginning of the line of source code.
Labels can be used only on executable statements inside methods.
You cannot use a
GoTo statement to branch from outside a
With...End With, or
Using...End Using construction to a label inside.
Try...Catch...Finally construction, the following rules apply to branching with the
|Block or region
|Branching in from outside
|Branching out from inside
|Only from a
Catch block of the same construction
|Only to outside the whole construction
|Only to outside the whole construction, or to the
Try block of the same construction
The following example uses the
GoTo statement to branch to line labels.
Public Sub Example1()
Dim number As Integer = 1
Dim sampleString As String
If number = 1 Then
sampleString = "Number equals 1"
sampleString = "Number equals 2"