• 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: syntax question: question marks
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: syntax question: question marks


  • Subject: Re: syntax question: question marks
  • From: Wade Tregaskis <email@hidden>
  • Date: Mon, 25 Aug 2003 13:48:07 +1000

This is a basic C language construct, which is essentially a shorthand if..else statement. The statement immediately preceding the question mark is evaluated - if it is true, the statement on the left of the colon is evaluated, otherwise the statement on the right is. e.g.

if (0x0 == myChar) {
gotToken = YES;
} else {
++tokenIndex;
}

... translates to:

(0x0 == myChar) ? (gotToken = YES) : ++tokenIndex;

You normally only find these in return statements and the like, or when translating 'binary' values (e.g. I can use (myBooleanValue ? @"YES" : @"NO") in NSLog's to show boolean values nicely). Otherwise, it's usually cleaner and simpler to use a normal if..else statement.

Wade Tregaskis
-- Sed quis custodiet ipsos custodes?
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >syntax question: question marks (From: <email@hidden>)

  • Prev by Date: Re: syntax question: question marks
  • Next by Date: Re: 10.3 and filesystem notifications
  • Previous by thread: Re: syntax question: question marks
  • Next by thread: Re: syntax question: question marks
  • Index(es):
    • Date
    • Thread