• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: If statement evaluation with logical AND
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: If statement evaluation with logical AND


  • Subject: Re: If statement evaluation with logical AND
  • From: Jeremy Dronfield <email@hidden>
  • Date: Wed, 8 Dec 2004 17:42:44 +0000

Thanks. That's very helpful. I take your point about caching the return value; in this case it isn't possible since the value will be different each time through the loop.

Regards,
Jeremy


On 8 Dec 2004, at 3:50 pm, Guy English wrote:

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:
email@hidden


This email sent to email@hidden


_______________________________________________ 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
References: 
 >If statement evaluation with logical AND (From: Jeremy Dronfield <email@hidden>)
 >Re: If statement evaluation with logical AND (From: Guy English <email@hidden>)

  • Prev by Date: Re: Responder Chain and NSDocumentController
  • Next by Date: Re: [OT] Document Icon Templates
  • Previous by thread: Re: If statement evaluation with logical AND
  • Next by thread: Printing a PDF file
  • Index(es):
    • Date
    • Thread