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

brncao

Board Regular
Joined
Apr 28, 2015
Messages
120
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.
 

joeu2004

Well-known Member
Joined
Mar 2, 2014
Messages
2,572
Office Version
2010
Platform
Windows
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:

Forum statistics

Threads
1,081,556
Messages
5,359,555
Members
400,533
Latest member
fpenning

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top