dawber39
asked on
Do-Loop
How can I change this code - to a (Do-Loop) statement?
Dim rates() As Decimal = {6.5D, 8.3D, 4, 2, 10.5D}
For Each rate As Decimal In rates
ratesLabel.Text = ratesLabel.Text _
& rate.ToString("N1") _
& ControlChars.NewLine
Next rate
Dim rates() As Decimal = {6.5D, 8.3D, 4, 2, 10.5D}
For Each rate As Decimal In rates
ratesLabel.Text = ratesLabel.Text _
& rate.ToString("N1") _
& ControlChars.NewLine
Next rate
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
homework... well, that's what I guessed :-)
let me give you a hint:
do loop is until a condition, yes?
so, assuming you keep the array, the loop has to START at the first item, and loop until the last item in the array.
that should be enough to find the code.
post your findings here, so we can help if there is some issue...
let me give you a hint:
do loop is until a condition, yes?
so, assuming you keep the array, the loop has to START at the first item, and loop until the last item in the array.
that should be enough to find the code.
post your findings here, so we can help if there is some issue...
ASKER
well - not really homework - but I will except your definition. This is what I have - and it does not work.
Dim rates() As Decimal = {6.5D, 8.3D, 4, 2, 10.5D}
Dim counter As Integer
Dim rate As String
Do Until counter = rates.Length
rate = rates(counter)
ratesLabel.Text = ratesLabel.Text _
& rate.ToString("N1") _
& ControlChars.NewLine
Loop
Dim rates() As Decimal = {6.5D, 8.3D, 4, 2, 10.5D}
Dim counter As Integer
Dim rate As String
Do Until counter = rates.Length
rate = rates(counter)
ratesLabel.Text = ratesLabel.Text _
& rate.ToString("N1") _
& ControlChars.NewLine
Loop
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It still does not work - I was doing some much more complicated than this - this little one is racking my brain.
Dim rates() As Decimal = {6.5D, 8.3D, 4, 2, 10.5D}
Dim counter As Integer
Dim rate As String
Do Until counter = rates.Length
rate = rates(counter)
ratesLabel.Text = ratesLabel.Text _
& rate.ToString("N1") _
& ControlChars.NewLine
counter = +1
Loop
Dim rates() As Decimal = {6.5D, 8.3D, 4, 2, 10.5D}
Dim counter As Integer
Dim rate As String
Do Until counter = rates.Length
rate = rates(counter)
ratesLabel.Text = ratesLabel.Text _
& rate.ToString("N1") _
& ControlChars.NewLine
counter = +1
Loop
did you initialize the counter variable correctly?
also, do you increment the counter variable correctly (do a debug and watch the value of counter) when running through the loop
also, do you increment the counter variable correctly (do a debug and watch the value of counter) when running through the loop
ASKER
I didn't increment the counter correctly -:
Dim rates() As Decimal = {6.5D, 8.3D, 4, 2, 10.5D}
Dim counter As Integer
Dim rate As Decimal
Do Until counter = rates.Length
rate = rates(counter)
ratesLabel.Text = ratesLabel.Text _
& rate.ToString("N1") _
& ControlChars.NewLine
counter = counter + 1
Loop
This one works - thanks for the direction
Dim rates() As Decimal = {6.5D, 8.3D, 4, 2, 10.5D}
Dim counter As Integer
Dim rate As Decimal
Do Until counter = rates.Length
rate = rates(counter)
ratesLabel.Text = ratesLabel.Text _
& rate.ToString("N1") _
& ControlChars.NewLine
counter = counter + 1
Loop
This one works - thanks for the direction
You also had
counter =+1
This is not correct. It should be
counter +=1 : This is the same thing as counter = counter + 1
This also works for:
counter *= variable
counter \= variable
counter -= variable
counter =+1
This is not correct. It should be
counter +=1 : This is the same thing as counter = counter + 1
This also works for:
counter *= variable
counter \= variable
counter -= variable
ASKER
Thank you - I also realized that I could do away with the rate variable and just work with (rates & counter) and insert this:
rates(counter).ToString("N 1")
I wasn't aware that - counter +=1 is the same thing as counter = counter + 1 - that is so cool
Thank you for your help
rates(counter).ToString("N
I wasn't aware that - counter +=1 is the same thing as counter = counter + 1 - that is so cool
Thank you for your help
ASKER