4 if/else
An important idea in programming is taking different actions depending on circumstances:
-
Have all the billing fields in the order form been filled out? If so, enable the Submit button.
-
Does the player have any lives left? If so, resume the game. If not, show the picture of the grave and play the sad music.
This sort of behavior is implemented using if and else, the syntax of which is:
if (conditional) { // Execute this code if the conditional evaluates to true } else { // Execute this code if the conditional evaluates to false }
You will not create a project in this chapter. Instead, consider the code examples carefully based on what you have learned in the last two chapters.
Here is an example of ...
Get Objective-C Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.