Thread: formatting
View Single Post
Old 04-02-2003, 07:50 AM   #31 (permalink)
jeffro
Person of interest
 
jeffro's Avatar
 
Join Date: Mar 2003
Location: New Jersey
Posts: 102
jeffro is on a distinguished road
Quote:
Ternary Operators are used to give variable a value, It returns a certain value, You can't really use it to execute, For example functions.
What!? In what language is this? For Java and Perl this is perfectly valid.

Code:
 x != null ? do(x) : doh() ;
sure this is invalid if doh() is a void method

Code:
printf( "%s\n", x != null ? do( x ) : doh() );
This wouldnt work, since printf needs a string to print, and doh() isnt going to return one. But yes, you can execute methods out of a ternary operator, you can even nest them!

Code:
return( ( gotAccount == YES ? ( status == 'A' ? YES : ( [self isSuspended] == YES ? YES : NO ) ) : NO ) );
jeffro
__________________
Jeffro
Linux counter#:213782
GnuPG ID: 406238E7
jeffro is offline   Reply With Quote