O'Reilly logo

Objective-C Quick Syntax Reference by Matthew Campbell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 14

image

If Statements

If Statements Defined

If statements are used when you want to make a choice to execute code based on the trueness of a condition. To make this work, you evaluate an expression that uses relational operators to yield a YES or NO result. If you evaluate an express to be true, then you can execute the code; otherwise you can ignore the code.

You need the if keyword and an expression here along with a code block to use the if statement.

if(1 < 2){    NSLog(@"That is true");}

The statement is saying that if 1 is less than 2, then execute the code that will print out the string “That is true” to the console log.

Else Keyword ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required