Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

1. The Basics > 1.9. Comparing Values in Objective-C with an If Statement

1.9. Comparing Values in Objective-C with an If Statement

Problem

You want to compare two values in Objective-C.

Solution

Use if statements. Please refer to the Discussion section of this recipe for more information about different scenarios under which you might want to use if statements.

Discussion

We use if statement in our everyday conversations. For instance, you might say “If I get a hold of him, I’ll tell him...” or “I would put the computer to sleep if it didn’t take so long to come back up”. All these statements have a condition. If statements in Objective-C also have a condition. You can even make them more sophisticated, having your app do something if a condition is met and something else if the condition is not met. The basic form of an if statement is:


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint