发布于 2015-07-05 11:55:26 | 196 次阅读 | 评论: 0 | 来源: 网络整理

if语句由一个布尔表达式后跟一个或多个语句。

语法:

在Objective-C编程语言的if语句的语法是:


if(boolean_expression)
{
   /* statement(s) will execute if the boolean expression is true */
}

如果布尔表达式的计算结果为true,那么里面的代码块,如果语句会被执行。如果布尔表达式计算为false,那么结束后的第一套代码的if语句(后右大括号)将被执行。

Objective-C语言的编程语言假设为true,任何非零和非空值,如果它是零或者为null,那么它被假定为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 20n" );
   }
   NSLog(@"value of a is : %dn", a);
 
   return 0;
}

上面的代码编译和执行时,它会产生以下结果:


2013-09-07 22:07:00.845 demo[13573] a is less than 20
2013-09-07 22:07:00.845 demo[13573] value of a is : 10
最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务