switch statement
提供: cppreference.com
![]() |
このページは、Google 翻訳を使って英語版から機械翻訳されました。
翻訳には誤りや奇妙な言い回しがあるかもしれません。文章の上にポインタをおくと、元の文章が見れます。誤りを修正して翻訳を改善する手助けをしてください。翻訳についての説明は、ここをクリックしてください。 |
一体型の引数の値に応じてコードを実行します
Original:
Executes code according to value of an integral argument
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.
どこで使用されるコードの多くの枝の1つまたはいくつかのうち、積分値に応じて実行する必要が.
Original:
Used where one or several out of many branches of code need to be executed according to an integral value.
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.
目次 |
[編集] 構文
switch ( expression ) {
|
|||||||||
[編集] 説明
expressionは、整数値に変換式でなければならない.
Original:
expression shall be an expression, convertible to an integer value.
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.
すべてconstant_expressionsは、この
switch
文内で一意となる整数値に変換定数式でなければならないOriginal:
All constant_expressions shall be constant expressions, convertible to an integer value, which is unique within this
switch
statementThe 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.
expressionが定義constant_expressioniのいずれかの値に等しい値に評価される場合は、statementi(存在する場合)およびそれ以降のすべてのステートメント(default_statement除いて、存在する場合)が実行されます。 expressionの値がconstant_expressionsのいずれとも一致しない場合は、存在する場合、default_statementが実行されます.
が使用可能であることを、覚えておくと便利です。その場合Original:
If the expression evaluates to a value, equal to the value of one of the defined constant_expressioni, the statementi (if present) and all subsequent statements (except default_statement, if present) are executed. If the value of the expression does not match any of the constant_expressions, the default_statement is executed if 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.
switch
文の実行は終了します. Original:
It is useful to note, that if the execution of subsequent statements is undesirable, the
ステートメントを破る</div> can be used. In that case the execution of the
Original:
break statement
The text has been machine-translated via [http://translate.google.com Google Translate].
You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions.
You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions.
switch
statement terminates. 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:
The following code shows several usage cases of the switch 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.
このコードを実行します
#include <iostream> int main() { int i = 2; switch (i) { case 1: std::cout << "1"; case 2: std::cout << "2"; //execution starts at this case label case 3: std::cout << "3"; case 4: case 5: std::cout << "45"; break; //execution of subsequent statements is terminated case 6: std::cout << "6"; } std::cout << '\n'; switch (i) { case 4: std::cout << "a"; default: std::cout << "d"; //there are no applicable constant_expressions //therefore default_statement is executed } std::cout << '\n'; switch (i) { case 4: std::cout << "a"; //nothing is executed } }
出力:
2345 d