What's the difference between Do While and Do Until?

brncao

Board Regular
Joined
Apr 28, 2015
Messages
147
Do Until thisBoolean = True... Will keep going "while" thisBoolean is False
Do While thisBoolean = False... Will keep going "until" thisBoolean is True.

They're like inverses of each other. Don't forget you can also use the NOT operator.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
What's the difference between Do While and Do Until?
Do Until thisBoolean = True... Will keep going "while" thisBoolean is False
Do While thisBoolean = False... Will keep going "until" thisBoolean is True.

What's the difference between IF(A1=B1,C1,D1) and IF(A1<>B1,D1,C1)? Why allow for both?

Rhetorical question. The point is: sometimes you feel like expressing the condition one way; sometimes the other way. And sometimes for good reason.

Suppose you want to continue looping so long as (while) A1=B1 and B1=C1 and C1=D1. It seems straight-forward to write Do While A1=B1 And B1=C1 And C1=D1 ... Loop or simply While A1=B1 And B1=C1 And C1=D1 ... WEnd.

Now suppose you want to loop until A1=B1 and B1=C1 and C1=D1. Isn't it more straight-forward to write Do Until A1=B1 And B1=C1 And C1=D1 than Do While Not (A1=B1 and B1=C1 and C1=D1)?

Yes, IMHO.

And potentially, the Do Until expression is more efficient: one less operation. But that depends on how clever the VBA interpreter is.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,549
Members
449,089
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top