ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

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

Here, we are going to learn how to print 1, 11, 31, 61, ... using Do Loop While in VB.Net?
Submitted by Nidhi, on December 06, 2020

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 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 »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.