If you have a statement in code like:
If X = true OR Y = true then…
If X = true, does it still evaluate to see if Y is true or does it skip the evaluation as being redundant?
If you have a statement in code like:
If X = true OR Y = true then…
If X = true, does it still evaluate to see if Y is true or does it skip the evaluation as being redundant?
if X is true it skips testing Y.
Btw, you can also write this as: if X or Y then
Also, there’s a similar situation with AND.
[code]dim f As Folderitem = getMyFile
if f <> nil and f.Exists then
//process
end[/code]
If f is nil it doesn’t test f.Exists.
Perfect. That explains what I was seeing. Thanks!
And it’s something that bites a lot of VB6 converts because in VB6 it evaluates the entire line. I like the Xojo way much better.
Xojo is much more like how most modern compiler treat boolean expression evaluation for AND / OR etc
IF condition1 or condition2 (and how ever many more you want)
need NOT evaluate condition2 and any others if condition1 is true since it wont matter what they return - the OR will be true
the same is true for AND
IF condition1 AND condition2 (and how ever many more you want)
need not evaluate condition2 etc if condition1 is FALSE because it wont matter
OR true false AND true false
true true true true true false
false true false false false false
I had no idea (or perhaps just forgot) that other languages did this differently. This seems only logical.
Allmost all languages have bitwise logic functions/operators and boolean logic (mostly short-circuiting) function/operators. & vs && in C++, C#, Java. In VB .NET And and Or are non-short-circuiting. Why? Because they do not only work on two booleans, but also on two integers. So MS introduced AndAlso and OrElse. Historically bitwise logic is of course older (Machine Language, Assembly) than boolean logic (ALGOL and its descendants).