GoTo statement transfers control unconditionally to a specified line in a procedure.
GoTostatement can branch only to lines in the procedure in which it appears.
GoTocan 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|
|Try block||Only from a
||Only to outside the whole construction|
|Catch block||Never allowed||Only to outside the whole construction, or to the
|Finally block||Never allowed||Never allowed|
The following example uses the
GoTo statement to branch to line labels.
Module GoToStatement Public Sub Example1() Dim number As Integer = 1 Dim sampleString As String If number = 1 Then GoTo Line1 Else GoTo Line2 End If Line1: sampleString = "Number equals 1" GoTo LastLine Line2: sampleString = "Number equals 2" LastLine: Console.WriteLine(sampleString) End Sub End Module