Visual Basic How to change a For Next Statement to a Do Loop Statement

Can anyone help me change this For Next Statement to a Do Loop Statement in Visual Basic?

  Private Sub FrmMain_Load(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles Me.Load
     
        ' fill the list box with values

        For dblRates As Double = 10 To 30 Step 5
            lstRate.Items.Add(dblRates.ToString)
        Next dblRates




    End Sub
anault24Asked:
Who is Participating?
 
Saurabh Singh TeotiaCommented:
I'm assuming you wanted to convert your for loop to do loop...then you can use this...

Private Sub FrmMain_Load(ByVal sender As Object, _
                         ByVal e As System.EventArgs) Handles Me.Load

' fill the list box with values
    dblRates = 10

    Do Until dblRates > 30


        lstRate.Items.Add (dblRates.ToString)


        dblRates = dblRates + 5

    Loop

End Sub

Open in new window

0
 
Fernando SotoRetiredCommented:
Hi anault24;

Here is another version using a do, loop.

Private Sub FrmMain_Load(ByVal sender As Object, _
       ByVal e As System.EventArgs) Handles Me.Load
     
    ' fill the list box with values
    dblRates As Double = 10
    Do While dbRates <= 30
        lstRate.Items.Add(dblRates.ToString)
        dbRates += 5
    Loop

End Sub

Open in new window

0
 
anault24Author Commented:
yes thank you very much!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.