Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
AND and OR evaluations in conditional statements
Message
From
11/04/1999 01:06:29
 
 
To
09/04/1999 01:59:06
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00206066
Message ID:
00207233
Views:
18
I think we all agree that it's best to use parentheses, but I suspect that the reason the question was asked in the first place was because someone was trying to maintain existing code that didn't contain parentheses and wasn't sure if it was working right, or needed to know how it was supposed to work in order to make changes.

Bonnie

>The best advice is to use parentheses, of course. This is 1000% safe and sure and atomic bomb proof! :) And costs almost nothing. Just a few more key strokes for the huge benefit of having zero possible bugs!
>
>NOT has the highest priority. AND is in the middle and OR is the last. This is the precedence of operators and not the order to evaluate the operands. So, "a or b and c" is in fact "a or (b and c)".
>
>That doesn't mean the operation between parentheses is evaluated first. a is evaluated first, followed by b and c. As many already said here, VFP will stop as soon as the final result is known. In this case, if a is .T., the (b and c) operation is never executed. This is good to know when the operands are function calls that have side effects (because they may be never executed). As a rule of thumb, do not use function calls in a logical operation, but use only variables.
>
>Vlad
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform