ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

VB.Net program to print the square of numbers from 1 to 5 using the GoTo statement

Here, we are going to learn how to print the square of numbers from 1 to 5 using the GoTo statement in VB.Net?
Submitted by Nidhi, on December 03, 2020

Here, we will print the square of numbers from 1 to 5 using the "GoTo" statement on the console screen.

Program/Source Code:

The source code to print the square of numbers from 1 to 5 using the "GoTo" statement is given below. The given program is compiled and executed successfully.

'VB.Net program to print the square of numbers 
'from 1 to 5 using "GoTo" statement.

Module Module1
    Sub Main()
        Dim count As Integer = 0

MyLabel:
        count = count + 1

        If count <= 5 Then
            Console.WriteLine("Num:{0}, Square:{1}", count, count * count)
            GoTo MyLabel
        End If

    End Sub
    
End Module

Output:

Num:1, Square:1
Num:2, Square:4
Num:3, Square:9
Num:4, Square:16
Num:5, Square:25
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 a variable count with an initial value of 0. Then we created the label MyLabel, which is used to transfer program control using the "GoTo" statement. After we increase the value of variable count one by one, and then we printed the square of numbers from 1 to 5 using the "GoTo" statement 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.