If statement evaluation with logical AND
If statement evaluation with logical AND
- Subject: If statement evaluation with logical AND
- From: Jeremy Dronfield <email@hidden>
- Date: Wed, 8 Dec 2004 12:40:54 +0000
This is a basic C question, and probably pretty lame to most of you,
but I can't find an answer in any of my C references. Say I have an if
statement with two or more conditions and a logical AND operator, like
so:
if (condition1 && condition2)
doSomething;
How are the conditions evaluated? What I mean is, is condition2
evaluated only if condition1 is true? Or are both conditions evaluated
and then, if both true, doSomething is called? If the latter is the
case (where condition2 is evaluated regardless of whether condition1 is
true), would it therefore be more efficient to use:
if (condition1)
if (condition2)
doSomething;
The reason I ask: I have an if statement which is executed many times
in a loop, where condition1 is unlikely to be true and condition2 is a
fairly expensive call.
Pardon my ignorance.
Regards,
Jeremy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden