2

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.)

Cœur
  • 37,241
  • 25
  • 195
  • 267
james.p
  • 21
  • 1
  • 3
  • 2
    If this is homework (which it clearly is) please tag it as such. Also, please show what you have already tried. See http://tinyurl.com/so-hints for more suggestions on improving your question. – RB. Aug 08 '12 at 09:01

2 Answers2

1

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;
Occidio
  • 165
  • 2
  • 7
1
   Sub Main()

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

            Console.ReadKey()

    End Sub
pingoo
  • 2,074
  • 14
  • 17