Objective-C if 语句
if 语句由一个布尔表达式后跟一个或多个语句组成。
语法
Objective-C 编程语言中 if 语句的语法为:
if(boolean_expression) {/* 如果 bool 表达式为 true,则这里语句会执行 */}
如果布尔表达式的计算结果为 true,则将执行 if 语句中的代码块。如果布尔表达式的计算结果为 false,则将执行 if 语句结束后(右大括号后)的第一组代码。
Objective-C 编程语言假设任何 non-zero 非零值和 non-null 非空值为 true,如果为零或空,则假设为 false。
流程图

实例
#import <Foundation/Foundation.h>int main () {/* local variable definition */int a = 10;/* check the boolean condition using if statement */if( a < 20 ) {/* if condition is true then print the following */NSLog(@"a is less than 20\n" );}NSLog(@"value of a is : %d\n", a);return 0;}
结果如下:
2022-07-07 22:07:00.845 demo[13573] a is less than 202022-07-07 22:07:00.845 demo[13573] value of a is : 10