• 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: 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

  • Follow-Ups:
    • Re: If statement evaluation with logical AND
      • From: Jeremy Dronfield <email@hidden>
References: 
 >If statement evaluation with logical AND (From: Jeremy Dronfield <email@hidden>)

  • Prev by Date: KVO, TableViews and Undo
  • Next by Date: Re: [OT] Document Icon Templates
  • Previous by thread: Re: If statement evaluation with logical AND
  • Next by thread: Re: If statement evaluation with logical AND
  • Index(es):
    • Date
    • Thread