3 Replies - 1987 Views - Last Post: 21 October 2008 - 06:30 AM Rate Topic: -----

#1 trevorkuznak  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-October 08

Display the squares of even integers 2 to 12

Post icon  Posted 16 October 2008 - 12:47 PM

Hey Guys,

I am tryign to code a procedure that displays the squares of the even integers from 2 through 12 in a label control. I have to display each square on a separate line in the control using the Do...Loop statement.

My application freezes for some reason.

Here is my code:

	Private Sub displayButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles displayButton.Click
		Dim num As Integer = 2
		Dim numSquared As Integer
		Do While num <= 12
			numSquared = (num + 2) * num

			squaresLabel.Text = squaresLabel.Text & Convert.ToString(numSquared) & ControlChars.NewLine
		Loop
	End Sub
End Class



Is This A Good Question/Topic? 0
  • +

Replies To: Display the squares of even integers 2 to 12

#2 trevorkuznak  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-October 08

Re: Display the squares of even integers 2 to 12

Posted 16 October 2008 - 12:56 PM

View Posttrevorkuznak, on 16 Oct, 2008 - 12:47 PM, said:

Hey Guys,

I am tryign to code a procedure that displays the squares of the even integers from 2 through 12 in a label control. I have to display each square on a separate line in the control using the Do...Loop statement.

My application freezes for some reason.

Here is my code:

	Private Sub displayButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles displayButton.Click
		Dim num As Integer = 2
		Dim numSquared As Integer
		Do While num <= 12
			numSquared = (num + 2) * num

			squaresLabel.Text = squaresLabel.Text & Convert.ToString(numSquared) & ControlChars.NewLine
		Loop
	End Sub
End Class




I think I got it:

Private Sub displayButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles displayButton.Click
		' calculates the squares of even integers from 2 through 12
		Dim num As Integer = 2
		Dim numSquared As Integer
		Do While num <= 12
			numSquared = num * num
			num = num + 2

			squaresLabel.Text = squaresLabel.Text & Convert.ToString(numSquared) & ControlChars.NewLine
		Loop
	End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

#3 Reverand Dave  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 3
  • View blog
  • Posts: 375
  • Joined: 27-July 08

Re: Display the squares of even integers 2 to 12

Posted 16 October 2008 - 01:33 PM

Without the incrementation of you integer within your loop, num will always = 2 and so it will never satisfy num <= 12 thus creating an infinte loop...
Was This Post Helpful? 0
  • +
  • -

#4 akhileshbc  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 9
  • View blog
  • Posts: 179
  • Joined: 27-September 08

Re: Display the squares of even integers 2 to 12

Posted 21 October 2008 - 06:30 AM

its vb.net
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1