Espaces de noms
Variantes
Affichages
Actions

while loop

De cppreference.com
< cpp‎ | language

 
 
Langage C++
Sujets généraux
Contrôle de flux
Instructions conditionnelles
Instructions d'itération
boucle while
boucle do-while
Instructions de saut
Fonctions
déclaration de fonction
expression lambda
fonction générique
spécificateur inline
spécification d'exception (obsolète)
spécificateur noexcept (C++11)
Exceptions
Espaces de noms
Types
spécificateur decltype (C++11)
Qualificatifs
qualificatifs const et volatile
qualificatifs de stockage
qualificatif constexpr (C++11)
qualificatif auto (C++11)
qualificatif alignas (C++11)
Initialisation
Littéraux
Expressions
opérateurs alternatifs
Utilitaires
Types
déclaration typedef
déclaration d'alias de type (C++11)
attributs (C++11)
Jette
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
conversions implicites
conversion const_cast
conversion static_cast
conversion dynamic_cast
conversion reinterpret_cast
conversions style C et style fonction
Allocation de mémoire
Classes
Qualificatifs spécifiques aux membres de classe
Fonctions membres spéciales
Modèles
classes génériques
fonctions génériques
spécialisation de modèles
paquets de paramètres (C++11)
Divers
Assembleur
 
Exécute une boucle .
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.
Utilisé lorsque le code doit être exécuté plusieurs fois tant qu'une condition est présent .
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.

Sommaire

[modifier] Syntaxe

while ( cond_expression ) loop_statement

[modifier] Explication

cond_expression doit être une expression dont le résultat est convertible en bool. Il est évaluée avant chaque exécution de loop_statement, qui est exécutée seulement si le cond_expression évalue à 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.
peut être utilisé comme terminaison déclaration .
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.
peut être utilisé comme raccourci .
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.

[modifier] Mots-clés

while

[modifier] Exemple

#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;
    }
}

Résultat :

10
2 4 6 8