×

VB.Net Programs

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

By Nidhi Last Updated : November 16, 2024

Reading a name and printing it 5 times using the Do Loop While in VB.Net

Here, we will read a number from the user and then print the entered name 5 times using the Do Loop While loop on the console screen.

Program/Source Code:

The source code to read a name and print 5 times using the Do Loop While loop is given below. The given program is compiled and executed successfully.

VB.Net code to read a name and print 5 times using the Do Loop While

'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: Shikar Dhawan
Shikar Dhawan
Shikar Dhawan
Shikar Dhawan
Shikar Dhawan
Shikar Dhawan

Press any key to continue . . .

Explanation:

In the above program, we created a module Module1 that contains a function Main(). In the Main() we created two variables name and count, here 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

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

VB.Net Basic Programs »


Comments and Discussions!

Load comments ↻





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