Objective-c-if-statement-in-objective-c
提供:Dev Guides
Objective-C-ifステートメント
*if* ステートメントは、ブール式とそれに続く1つ以上のステートメントで構成されます。
構文
Objective-Cプログラミング言語のifステートメントの構文は次のとおりです-
if(boolean_expression) {
/*statement(s) will execute if the boolean expression is true*/
}
ブール式が true と評価された場合、ifステートメント内のコードブロックが実行されます。 ブール式の評価が 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 20\n" );
}
NSLog(@"value of a is : %d\n", 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