The if Statement

The Objective-C programming language provides a general decision-making capability in the form of a language construct known as the if statement. The general format of this statement is shown here:

if ( expression )    program statement

Imagine that you could translate a statement such as “If it is not raining, then I will go swimming” into the Objective-C language. Using the previous format for the if statement, this might be “written” in Objective-C as follows:

if ( it is not raining )    I will go swimming

The if statement is used to stipulate execution of a program statement (or statements, if enclosed in braces) based on specified conditions. I will go swimming if it is not raining. Similarly, in the program statement

Get Programming in Objective-C, Fifth Edition 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.