Home >>VB.Net Programs >VB.Net program to print the square of numbers from 1 to 5

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

Write a VB.Net program to print the square of numbers from 1 to 5

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

Program :

Below is the source code for printing the square of numbers from 1 to 5 using the 'GoTo' statement. The program given is compiled and successfully executed.

Example


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

Explanation:

We created a Module1 module in the program above that contains the Main() method. We created a variable count in the Main() method with an initial value of 0. Then we developed the MyLabel label, which is used using the "GoTo" statement to transfer program control. As the value of the variable count is raised one by one, and then the square of numbers from 1 to 5 is written using the "GoTo" statement on the console screen.


No Sidebar ads