×

VB.Net Programs

VB.Net program to print 1, 11, 31, 61, ... using Do Loop While

By Nidhi Last Updated : November 16, 2024

Printing 1, 11, 31, 61, ... using Do Loop While in VB.Net

Here, we will print the given series using the Do Loop While loop on the console screen.

Program/Source Code:

The source code to print 1,11,31,61, ... using the Do Loop While loop is given below. The given program is compiled and executed successfully.

VB.Net code to print 1, 11, 31, 61, ... using Do Loop While

'VB.Net program to print 1,11,31,61, ... using 
'"Do Loop While" loop.

Module Module1

    Sub Main()
        Dim num As Integer = 1
        Dim cnt As Integer = 1
        Dim dif As Integer = 10

        Do
            Console.Write("{0} ", num)

            num = num + dif
            dif = dif + 10

            cnt = cnt + 1
        Loop While cnt <= 5

        Console.WriteLine()
    End Sub

End Module

Output:

1 11 31 61 101
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 three variables num, cnt, and dif that are initialized with 1, 1, and 10.

Dim num As Integer = 1
Dim cnt As Integer = 1
Dim dif As Integer = 10

Do
    Console.Write("{0} ", num)

    num = num + dif
    dif = dif + 10

    cnt = cnt + 1
Loop While cnt <= 5

Console.WriteLine()

In the above code, we used the counter variable cnt to execute the loop 5 times, and, here num and dif variables are used to calculate numbers according to series using the Do Loop While loop and then print series on the console screen.

VB.Net Basic Programs »


Comments and Discussions!

Load comments ↻





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