名前空間
変種
操作

while loop

提供: cppreference.com
< cpp‎ | language
2012年10月26日 (金) 07:00時点におけるTranslationBot (トーク | 投稿記録)による版

(差分) ←前の版 | 最新版 (差分) | 次の版→ (差分)

 
 
C++言語
一般的なトピック
フロー制御
条件付き実行文
繰り返し文 (ループ)
while
do-while
ジャンプ文
関数
関数宣言
ラムダ関数宣言
inline 指定子
例外指定 (C++20未満)
noexcept 指定子 (C++11)
例外
名前空間
指定子
decltype (C++11)
auto (C++11)
alignas (C++11)
記憶域期間指定子
初期化
代替表現
リテラル
ブーリアン - 整数 - 浮動小数点
文字 - 文字列 - nullptr (C++11)
ユーザ定義 (C++11)
ユーティリティ
属性 (C++11)
typedef 宣言
型エイリアス宣言 (C++11)
キャスト
暗黙の変換 - 明示的な変換
static_cast - dynamic_cast
const_cast - reinterpret_cast
メモリ確保
クラス
クラス固有の関数特性
特別なメンバ関数
テンプレート
その他
 
ループを実行.
Original:
Executes a loop.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
コー​​ドには、いくつかの条件が存在している間、何度も実行する必要がどこに使用され.
Original:
Used where code needs to be executed several times while 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.

目次

構文

while ( cond_expression ) loop_statement

説明

cond_expressionは、その結果boolに変換可能な表現でなければならない。それはloop_statementcond_expressionと評価された場合にのみ実行されtrue、それぞれの実行前に評価されます.
Original:
cond_expression shall be an expression, whose result is convertible to bool. It is evaluated before each execution of loop_statement, which is only executed if the cond_expression evaluates to true.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
は文の終端として使用することができます.
Original:
If the execution of the loop needs to be terminated at some point,
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
はショートカットとして使用することができます.
Original:
If the execution of the loop needs to be continued at the end of the loop body,
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

キーワード

while

#include <iostream>
 
int main()
{
    int i = 0;
    while (i < 10) i++;
 
    std::cout << i << '\n';
 
    int j = 2;
    while (j < 9) {
        std::cout << j << " ";
        j += 2;
    }
}

出力:

10
2 4 6 8