Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
AND and OR evaluations in conditional statements
Message
De
09/04/1999 02:14:52
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00206066
Message ID:
00206797
Vues:
17
>Can you show me an example of AND getting evaluated before OR is when the OR is to the left of the AND?

It's not a matter of time sequence of evaluations for operators. The operator precedence gives only the operand grouping. The order (in time) to evaluate each operation/operands depends on the compiler and it doesn't matter as long as the result is correct. (It doesn't matter for logical operation if there are no functions with side effects involved. In many cases, it matters for arithmetic operations because of the unavoidable roundings. Some programs will change the order in arithmetic operation evaluation just to get the best possible precision.)

>If I ask ? 5 + 2 * 7 the reply is 19 because the * is done before the + due to precedence. But if I ask ? a OR b AND c and a is true the AND never gets evaluated, if I put the and first then the and gets done first. It certainly appears that the expression is being evaled from left to right regardless of teh and/or distribution.

While f() + g() * h() may give you the following operand evaluation order in time: f, g, h. (Which is what VFP does!) This doesn't mean + is evaluated before *.

Vlad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform