The conditional operator is rather strange, but is very useful. (By the way, an operator is something that acts upon two or more values, such as the addition ‘+’ operator.) In many cases (or at least frequent enough for them to make up a new operator), programmers have had to determine the largest or the smallest of two values, and use the corresponding (largest or smallest) value. Normally, the code would be like this:
if (number1 > number2)
return number1;
else
return number2;
This became cumbersome. Introducing, the conditional operator:
return (number1 > number2) ? number1 : number2;
This does the same thing as the code above. The parts in bold are the required syntax; any valid expression, constant, or variable can be placed in between.
There are three parts to the conditional operator: the condition, and the two “paths”.
The condition is a boolean condition, one that would otherwise trigger an if-statement. If that is true, number1 is returned; otherwise number2 is returned.
That’s all there is to it.

Ethan
/ November 10, 2010Ugh!!! Hurry up! I need to learn objective C before the iPhone app bubble bursts!
inspire48
/ November 10, 2010I’m sorry! I’ve been swamped in obligations recently…but Lesson 4 is up: http://cupsofcocoa.wordpress.com/2010/11/10/objective-c-lesson-4-if-statements-and-booleans/
Check it out; more content (I’m planning two more Extensions, and maybe another Lesson) by this weekend. Promise! Thanks for coming by!
Ethan
/ November 15, 2010Haha! Thanks man! … Just hassling you, just hasslin’.