Is there any short syntax for if-else statement in objective C like PHP:
if($value) return 1; else return 0;
shorter version:
return $value?1:0;
An if statement can be followed by an optional else if...else statement, which is very useful to test various conditions using single if...else if statement. An if can have zero or one else's and it must come after any else if's. An if can have zero to many else if's and they must come before the else.
The syntax of an if statement in Objective-C programming language is − if(boolean_expression) { /* statement(s) will execute if the boolean expression is true */ } If the boolean expression evaluates to true, then the block of code inside the if statement will be executed.
Objective-C is the primary programming language you use when writing software for OS X and iOS. It's a superset of the C programming language and provides object-oriented capabilities and a dynamic runtime.
Yes.
Example (pseudo):
value = (expression) ? (if true) : (if false);
Based on your example (valid code):
BOOL result = value ? YES : NO;
It's exactly the same in both languages, except you typically don't find $
signs in Objective-C variable names.
if(value) return 1; else return 0;
return value?1:0;
You should also keep in mind that the conditional operator ?:
isn't a shorthand for an if-else statement so much as a shorthand for a true vs false expression. See the PHP manual.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With