D-programming-if-statement
提供:Dev Guides
Dプログラミング-ifステートメント
*if* ステートメントは、ブール式とそれに続く1つ以上のステートメントで構成されます。
構文
Dプログラミング言語のifステートメントの構文は-
if(boolean_expression) {
/*statement(s) will execute if the boolean expression is true*/
}
ブール式の評価が true の場合、ifステートメント内のコードブロックが実行されます。 ブール式が false と評価された場合、ifステートメントの終了後(閉じ中括弧の後)の最初のコードセットが実行されます。
Dプログラミング言語は、すべての*非ゼロ*および*非ヌル*値を true と見なし、ゼロ*または *null の場合、 false 値と見なされます。
流れ図
例
import std.stdio;
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*/
writefln("a is less than 20" );
}
writefln("value of a is : %d", a);
return 0;
}
上記のコードをコンパイルして実行すると、次の結果が生成されます-
a is less than 20;
value of a is : 10