Re: If statement evaluation with logical AND
Re: If statement evaluation with logical AND
- Subject: Re: If statement evaluation with logical AND
- From: Guy English <email@hidden>
- Date: Wed, 8 Dec 2004 10:50:47 -0500
On Wed, 8 Dec 2004 12:40:54 +0000, Jeremy Dronfield
<email@hidden>
> What I mean is, is condition2 evaluated only if condition1 is true?
Yes. Thats why you can have code like:
if ( myPointer != NULL && myPointer->someValue != 0 ) blah( myPointer );
> 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.
What you ideally want to do is avoid calling condition2 at all. If
it's result wont change during the run of the loop then cache it's
return value. You can do this either internally to the object you're
calling or loop through all your objects and stash condition2s results
in a lookup table.
> Pardon my ignorance.
Nonsense - it's not the list for it maybe but it's a valid question.
Take care,
Guy
_______________________________________________
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