• 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
If statement evaluation with logical AND
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: If statement evaluation with logical AND
      • From: Guy English <email@hidden>
    • Re: If statement evaluation with logical AND
      • From: j o a r <email@hidden>
  • Prev by Date: Re: Drag and drop color swatches
  • Next by Date: Re: If statement evaluation with logical AND
  • Previous by thread: RE: int <-> float formatters?
  • Next by thread: Re: If statement evaluation with logical AND
  • Index(es):
    • Date
    • Thread