how to convert the for loop to while loop

Recommended Answers

All 4 Replies

please any body >> help me??

we'll have to see the actual code to give a definitive answer. But basically a for loop has known limits and automatic incrementation, or decrementation, until the limit is reached. A while loop relies on a condition, or conditions, to be met before ending the loop, and doesn't usually rely on incrementing a value. To convert you'll have to code the limits and the increment separately.

commented: Good explanation! +8

This is a sample code.

'For loop
dim i as integer
for i = 0 to 5
    debug.print i
next

'while loop
dim i as integer
i = 0
while i <> 5
    i = i + 1
    debug.print i
loop
Dim i As Integer
    For i = 0 To 5
        Debug.Print i
    Next
    i = 0
    While i <= 5
        Debug.Print i
        i = i + 1
    Wend
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.