Home >>VB.Net Programs >VB.Net program to print 1, 11, 31, 61, ..., 10 times using GoTo statement
Here, using the 'GoTo' statement on the console screen, we will print the given series.
Program :
source Code for printing 1,11,31,61,... Using the "GoTo" statement 10 times as given below. The program given is compiled and successfully executed.
Example
Module Module1
Sub Main()
Dim num As Integer = 1
Dim cnt As Integer = 1
Dim dif As Integer = 10
MyLabel:
Console.Write("{0}, ", num)
num = num + dif
dif = dif + 10
cnt = cnt + 1
If cnt <= 10 Then
GoTo MyLabel
End If
Console.WriteLine()
End Sub
End Module
Explanation:
We created a Module1 module in the program above that contains the Main() method. Three variables num, cnt, and dif that are initialized with 1,1, and 10 respectively were created in the Main() method. Then we developed the MyLabel label, which is used using the "GoTo" statement to pass program control.
MyLabel: Console.Write("{0}, ", num) num = num + dif dif = dif + 10 cnt = cnt + 1 If cnt <= 10 Then GoTo MyLabel End If
We find the given series on the console screen by using the above code.