Cplusplus-cpp-if-statement
提供:Dev Guides
C ++ ifステートメント
*if* ステートメントは、ブール式とそれに続く1つ以上のステートメントで構成されます。
構文
C ++のifステートメントの構文は-
if(boolean_expression) {
//statement(s) will execute if the boolean expression is true
}
ブール式が true と評価された場合、ifステートメント内のコードブロックが実行されます。 ブール式の評価が false の場合、ifステートメントの終了後(閉じ中括弧の後)の最初のコードセットが実行されます。
流れ図
例
#include <iostream>
using namespace std;
int main () {
//local variable declaration:
int a = 10;
//check the boolean condition
if( a < 20 ) {
//if condition is true then print the following
cout << "a is less than 20;" << endl;
}
cout << "value of a is : " << a << endl;
return 0;
}
上記のコードをコンパイルして実行すると、次の結果が生成されます-
a is less than 20;
value of a is : 10