Re: syntax question: question marks
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.