Skip to main content

Do While

This is very similar to ours Do Loop we just used above. The only difference is, instead of the condition we set (iMyNumber < 1000) being checked AFTER the Do has run at least once, the Do While will check the condition BEFORE it runs. Let’s say our Variable iMyNumber has already had the Value 101 parsed to it. In the Do Loop we used above, it will NOT know the Value of iMyNumber until it has run ONCE. This would mean our Variable would come out of the Do Loop with a Value of 102. But in the Do While below, it would never even enter the Loop:-



Sub My_DoWhile()

Dim iMyNumber as Integer


Do While iMyNumber < 1000

iMyNumber = 1 + iMyNumber

Range(“b2”).Value = iMyNumber


End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *