If I have the following …
a OrElse b
… and a is True then clearly b is never evaluated. But if I add an Or, then what?
a OrElse b Or c
Does/should c get evaluated? And what if I put in some brackets?
Apologies if this is basic. Of course I can test for the answer myself but I can’t find this question answered here or elsewhere. Lots of questions dealing with Or versus OrElse but nothing dealing with Or with OrElse
This is an operator precedence problem. The relevant documentation is here:
http://msdn.microsoft.com/en-us/library/fw84t893.aspx?ppud=4
The important excerpts:
and
So what we learn here is that Or and OrElse have the same precedence and that operators with the same precedence are evaluated from left to right.
Therefore, I would expect that in cases where
ais true,bis not evaluated. However,cstill will be. In cases whereais false,bis evaluated and regardless of theb‘s value the Or operator will evaluatec. So, yes,cis always evaluated.As a practical matter, you should generally prefer
OrElsein your code unless you have a good reason to useOr.Orexists now mainly for backwards compatibility.