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

Here, we are going to learn how to read a name and print 5 times using GoTo statement in VB.Net?
Submitted by Nidhi, on December 03, 2020 [Last updated : March 05, 2023]

Reading a name and print 5 times using GoTo statement in VB.Net

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

Program/Source Code:

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

VB.Net code 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.

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: Rahul
Name: Rahul
Name: Rahul
Name: Rahul
Name: Rahul
Name: Rahul
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 three variables name and count. Then we created the label MyLabel, which is used to transfer program control using the "GoTo" statement. 

After that, we read the name from the user and then printed the entered name 5 times on the console screen.

VB.Net Basic Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.