Home >>VB.Net Built-in Functions >VB.Net program to print 1, 11, 31, 61, ... using Do While Loop
Here, using the Do Loop While loop on the console screen, we will print the series given.
Program :
Code source for printing 1,11,31,61,... It is given below using the Do Loop While loop. The program given is compiled and successfully executed.
'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
Explanation:
We created a Module1 module in the above program that contains the function Main(). Three variables num, cnt, and dif have been created in the main() and 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, to run the loop 5 times, we used the counter variable cnt, and here num and dif variables are used to measure numbers by series using the Do Loop While loop and then print series on the console screen.