if statement
提供: cppreference.com
|
|
このページは、Google 翻訳を使って英語版から機械翻訳されました。
翻訳には誤りや奇妙な言い回しがあるかもしれません。文章の上にポインタをおくと、元の文章が見れます。誤りを修正して翻訳を改善する手助けをしてください。翻訳についての説明は、ここをクリックしてください。 |
<metanoindex/>
条件付きでコードを実行.
Original:
Conditionally executes code.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
コードには、いくつかの条件が存在する場合にのみ実行する必要がある場合に使用.
Original:
Used where code needs to be executed only if some condition is present.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
構文
if ( expression ) statement_true
|
|||||||||
if ( expression ) statement_true else statement_false
|
|||||||||
説明
expressionは、
boolに変換式でなければならない.Original:
expression shall be an expression, convertible to
bool.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
それは
trueに評価された場合、制御がstatement_trueに渡され、statement_false(存在する場合)が実行されません.Original:
If it evaluates to
true, control is passed to statement_true, statement_false (if present) is not executed.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
そうしないと、コントロールがstatement_falseに渡され、statement_trueは実行されません.
Original:
Otherwise, control is passed to statement_false, statement_true is not executed.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
キーワード
例
次の例では、
if文のいくつかの使用例を示しています
Original:
The following example demonstrates several usage cases of the
if statement
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Run this code
#include <iostream>
int main()
{
int i = 2;
if (i > 2) {
std::cout << "first is true" << '\n';
} else {
std::cout << "first is false" << '\n';
}
i = 3;
if (i == 3) std::cout << "i == 3" << '\n';
if (i != 3) std::cout << "i != 3" << '\n';
else std::cout << "i != 3 is false" << '\n';
}
出力:
first is false
i == 3
i != 3 is false