Printing square numbers in Visual Basic using loops

7.7k views Asked by At

I'm trying to print a list of square numbers in Visual Basic using a for loop. I'm a newbie, and find this pretty hard. The program I'm writing is supposed to print a list of the squares of numbers e.g. (1, 4, 9, 16, and so on.)

2

There are 2 answers

0
pingoo On
   Sub Main()

            For number As Integer = 1 To 1000
                Console.WriteLine("Square of {0} : {1}", number, number * number)
            Next

            Console.ReadKey()

    End Sub
0
Occidio On

You could add a counter to your loop then each time the loop is executed increment it. Then inside the loop you would just need to times the counter with itself for the square.

square = counter*counter;