Home >>VB.Net Programs >VB.Net program to read a name and print 5 times using GoTo statement

VB.Net program to read a name and print 5 times using GoTo statement

Write a VB.Net program to read a name and print 5 times using GoTo statement

Here, we'll read a user string and print the entered name on the console screen 5 times.

Program :

Below is the source code to read and print a name 5 times using the 'GoTo' statement. The program given is compiled and successfully executed.

Example


Module Module1
    Sub Main()
        Dim name As String
        Dim count As Integer = 0
        Console.Write("Enter Name : ")
        name = Console.ReadLine()
MyLabel:
        count = count + 1
        If count <= 5 Then
            Console.WriteLine("Name : {0}", name)
            GoTo MyLabel
        End If
    End Sub
End Module
	
Output:
Enter Name : Test
Name : Test
Name : Test
Name : Test
Name : Test
Name : Test

Explanation:

We created a Module1 module in the program above that contains the Main() method. We created the name and count of three variables in the Main() method. Then we developed the MyLabel label, which is used using the "GoTo" statement to pass program control.

After that, we read the user's name and then printed the given name on the console screen 5 times.