Home >>VB.Net Built-in Functions >VB.Net program to Enter a name and print 5 times using Do While Loop

VB.Net program to Enter a name and print 5 times using Do While Loop

Write a VB.Net program to Enter a name and print 5 times using Do While Loop

Here, we can read the user's number and then print the name entered 5 times on the console screen using the Do Loop While loop.

Program :

Below is the source code for reading and printing a name 5 times using the Do Loop While loop. The program given is compiled and successfully executed.

'VB.Net program to read a name and print 5 times

'using "Do Loop While" loop.


Module Module1
    Sub Main()
        Dim name As String = ""
        Dim count As Integer = 1
        Console.Write("Enter Name: ")
        name = Console.ReadLine()
        Do
            Console.WriteLine("{0} ", name)
            count = count + 1
        Loop While count <= 5
        Console.WriteLine()
    End Sub
End Module
	
Output:
Enter Name: Rohit Sharma
Rohit Sharma
Rohit Sharma
Rohit Sharma
Rohit Sharma
Explanation:

We created a Module1 module in the above program that contains the function Main(). Two variables name and count were created in the Main(), here the variable name is initialized with an empty string, and the variable count is initialized with 1.

Console.Write("Enter Name: ")
name = Console.ReadLine()
Do
    Console.WriteLine("{0} ", name)
    count = count + 1
Loop While count <= 5

We used the counter variable count to run the loop 5 times in the above code, and here we read a user name and then print the name 5 times using the Do Loop While loop.


No Sidebar ads