Home »
VB.Net »
VB.Net Programs
VB.Net program to demonstrate the use of the GoTo statement
Here, we are going to demonstrate the use of the GoTo statement in VB.Net.
Submitted by Nidhi, on December 03, 2020 [Last updated : March 05, 2023]
GoTo statement in VB.Net
Here, we will demonstrate the use of the "GoTo" statement to print numbers from 1 to 10 on the console screen.
Program/Source Code:
The source code to demonstrate the use of the "GoTo" statement is given below. The given program is compiled and executed successfully.
VB.Net code to demonstrate the example of GoTo statement
'VB.Net program to demonstrate the
'use of the "GoTo" statement.
Module Module1
Sub Main()
Dim num As Integer = 0
MyLabel:
num = num + 1
If num <= 10 Then
Console.Write("{0} ", num)
GoTo MyLabel
End If
Console.WriteLine()
End Sub
End Module
Output:
1 2 3 4 5 6 7 8 9 10
Press any key to continue . . .
Explanation:
In the above program, we created a module Module1 that contains a Main() method. In the Main() method, we created a variable num of Integer type, which is initialized with 0. Then we created the label MyLabel, which is used to transfer program control using the "GoTo" statement. Then we increased the value of variable num by one till 10.
If num <= 10 Then
Console.Write("{0} ", num)
GoTo MyLabel
End If
In the above code, program control will transfer each time until the value of variable num is less than equal to 10 and print the number on the console screen.
VB.Net Basic Programs »