Mail Archives: djgpp/2000/01/17/06:44:54
On Sun, 16 Jan 2000 21:53:16 Adam Schrotenboer wrote:
>Does it have any '||' in it?? Otherwise, the C def req's shortcut
>evaluation, so yes, if I understand correctly, it will exit out as soon as
>the statement is known to be false. (A little vague, I know. I only know a
>little bit from some comp.sci courses I took a few years back)
>
--
This is known as "short circuit" boolean eval. And it can happen even if a bool statement has an || in it. Example:
if (
((a==x)||(a==y))
&& ((b==x)||(b==y))
&& ((c==x)||(c==y))
)
{
do_something_cool();
}
If the '||' in the first paren group evaluates false, the whole statement bombs out even if the '||' in the second and third paren evaluates true.
Generally for the case:
if (a && b && c [&& ...])
{
do_something_cool();
}
where a, b, c, can be a simple or complex boolean expression, if the first expression evaluates falls, the entire statement is false.
In another case:
if (
((a==x) || (a==y))
&& ((b==x) || (b==y))
|| ((c==x) || (c==y))
)
{
do_something_cool();
}
would require a complete boolean eval, since, simplified, it is equivalent to:
if (a && b || c)
{
do_something_cool();
}
and '&&' has greater precedence than '||' and will require the entire statement to be evaluated.
Hope this helps...
oOOOo Synflood oOOOo
Join 18 million Eudora users by signing up for a free Eudora Web-Mail account at http://www.eudoramail.com
- Raw text -