Espaces de noms
Variantes
Affichages
Actions

do-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ésente. le code est exécuté au moins une fois .
Original:
Used where code needs to be executed several times while some condition is present. the code is executed at least once.
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

do loop_statement while ( cond_expression )

[modifier] Explication

cond_expression doit être une expression dont le résultat est convertible en bool. Il est évalué après chaque exécution de loop_statement. La boucle continue l'exécution que si la cond_expression évalue à true .
Original:
cond_expression shall be an expression, whose result is convertible to bool. It is evaluated after each execution of loop_statement. The loop continues execution only 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

do, while

[modifier] Exemple

#include <iostream>
 
int main()
{
    int i = 0;
    do i++;
    while (i < 10);
 
    std::cout << i << '\n';
 
    i = 11;
    do i = i + 10;
    while (i < 10); //the code is executed even if the condition is false before the loop
 
    std::cout << i << '\n';
 
    int j = 2;
    do {
        j += 2;
        std::cout << j << " ";
    } while (j < 9);
}

Résultat :

10
21
4 6 8 10