To: djgpp AT delorie DOT com Date: Mon, 17 Jan 2000 09:34:52 0000 From: "Nimrod Alonzo Abing" Message-ID: Mime-Version: 1.0 X-Sent-Mail: off X-Mailer: MailCity Service Subject: Re: Question on 'if' statements... X-Sender-Ip: 208.160.246.197 Organization: QUALCOMM Eudora Web-Mail (http://www.eudoramail.com:80) Content-Type: text/plain; charset=us-ascii Content-Language: en Content-Transfer-Encoding: 7bit Reply-To: djgpp AT delorie DOT com 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