goto statement
提供: cppreference.com
![]() |
このページは、Google 翻訳を使って英語版から機械翻訳されました。
翻訳には誤りや奇妙な言い回しがあるかもしれません。文章の上にポインタをおくと、元の文章が見れます。誤りを修正して翻訳を改善する手助けをしてください。翻訳についての説明は、ここをクリックしてください。 |
新しい場所に制御を移し.
Original:
Transfers control to a new location.
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 when it is otherwise impossible to transfer control to the desired location using conventional constructs.
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.
目次 |
[編集] 構文
goto label
|
|||||||||
[編集] 説明
goto文に制御を移しlabelで指定された場所へ。goto文は、でなければなりませんlabelそれと同じ機能を参照しています。goto文の転送は後方にコントロールしている場合、まだlabel時に初期化されていないすべてのオブジェクトが破棄されますそれは、そうすることは、オブジェクトの初期化.
Original:
The goto statement transfers control to the location specified by label. The goto statement must be in the same function as the label it is referring. If goto statement transfers control backwards, all objects that are not yet initialized at the label are destructed. It is illegal to transfer control forwards if doing so would skip initialization of an object.
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> struct Object { ~Object() { std::cout << "d"; } }; int main() { int a = 10; //loop using goto label: Object obj; std::cout << a << " "; a = a - 2; if (a != 0) { goto label; //causes obj to be destructed } std::cout << '\n'; //get out of multi-level loop easily for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { std::cout << "(" << x << ";" << y << ") " << '\n'; if (x + y >= 3) { goto endloop; } } } endloop: std::cout << '\n'; return 0; //causes obj to be destructed }
出力:
10 d8 d6 d4 d2 (0;0) (0;1) (0;2) (1;0) (1;1) (1;2) d