Ad space (banner)
Lesson 6 / 20

Repeating (the Do While statement)

This lesson covers the Do While statement, which repeats only while a condition holds.

Writing Do While condition ... Loop repeats the block for as long as the condition is true.

The sample code joins the number into a message and increases it by one while count is 3 or less.

A common early stumble is forgetting to update the counter inside the loop and ending up in an infinite loop. Whenever you use Do While, make sure something in the body eventually makes the condition false.

In professional work, Do While is used for work such as searching until a cell meeting some condition is found.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run VBA directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)