ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

VB.Net program to print 1, 11, 31, 61, ..., 10 times using GoTo statement

Here, we are going to learn how to print 1, 11, 31, 61, ..., 10 times using GoTo statement in VB.Net?
Submitted by Nidhi, on December 03, 2020

Here, we will print the given series using the "GoTo" statement on the console screen.

Program/Source Code:

The source code to print 1,11,31,61, ... 10 times using the "GoTo" statement is given below. The given program is compiled and executed successfully.

'VB.Net program to print 1, 11, 31, 61, ... 
'10 times using "GoTo" statement.

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

MyLabel:
        Console.Write("{0}, ", num)

        num = num + dif
        dif = dif + 10
        cnt = cnt + 1

        If cnt <= 10 Then
            GoTo MyLabel
        End If

        Console.WriteLine()
    End Sub
    
End Module

Output:

1, 11, 31, 61, 101, 151, 211, 281, 361, 451,
Press any key to continue . . .

Explanation:

In the above program, we created a module Module1 that contains a Main() method. In the Main() method, we created three variables num, cnt, and dif that are initialized with 1,1, and 10 respectively. Then we created the label MyLabel, which is used to transfer program control using the "GoTo" statement.

MyLabel:
    Console.Write("{0}, ", num)

    num = num + dif
    dif = dif + 10
    cnt = cnt + 1

    If cnt <= 10 Then
        GoTo MyLabel
    End If

Using the above code we find the given 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.