Home >>VB.Net Programs >VB.Net program to print the table of given number using GoTo statement

VB.Net program to print the table of given number using GoTo statement

Write a VB.Net program to print the table of given number using GoTo statement

Here, we will read a number from the user and then print the table of the specified number on the console screen using the 'GoTo' statement.

Program :

Below is the source code for printing the table of the specified number using the 'GoTo' statement. The program given is compiled and successfully executed.

Example


Module Module1
    Sub Main()
        Dim count As Integer = 0
        Dim num As Integer = 0
        Console.Write("Enter number: ")
        num = Integer.Parse(Console.ReadLine())
MyLabel:
        count = count + 1
        If count <= 10 Then
            Console.WriteLine("{0}X{1}={2}", num, count, num * count)
            GoTo MyLabel
        End If
    End Sub
End Module
	
Output:
Enter number: 5
5X1=5
5X2=10
5X3=15
5X4=20
5X5=25
5X6=30
5X7=35
5X8=40
5X9=45
5X10=50

Explanation:

We created a Module1 module in the program above that contains the Main() method. In the Main() method, we created two Integer type variables, num and count, initialized with 0.0. Then we developed the MyLabel label, which is used using the "GoTo" statement to transfer program power. We then read the value of the user's variable number. We then expanded the variable count value by one to 10.

If count <= 10 Then
    Console.WriteLine("{0}X{1}={2}", num, count, num * count)
    GoTo MyLabel
End If

The program control in the above code will transfer each time until the value of the variable count is less than 10, and the table of a given number will be printed by multiplying the number by the count on the console screen.


No Sidebar ads