[ Web Proxy ]
URL:
Viewing: https://fr.cppreference.com/cpp/language/if [Back]  [Original]

if statement cppreference.com
cppreference.com
Espaces de noms
Variantes

if statement

De cppreference.com

<metanoindex/>

 
 
Langage C++
Sujets gnraux
Contrle de flux
Instructions conditionnelles
Instructions d'itration
Instructions de saut
Fonctions
dclaration de fonction
expression lambda
fonction gnrique
spcificateur inline
spcification d'exception (obsolte)
spcificateur noexcept (C++11)
Exceptions
Espaces de noms
Types
spcificateur decltype (C++11)
Qualificatifs
qualificatifs const et volatile
qualificatifs de stockage
qualificatif constexpr (C++11)
qualificatif auto (C++11)
qualificatif alignas (C++11)
Initialisation
Littraux
Expressions
oprateurs alternatifs
Utilitaires
Types
dclaration typedef
dclaration 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 mmoire
Classes
Qualificatifs spcifiques aux membres de classe
Fonctions membres spciales
Modles
classes gnriques
fonctions gnriques
spcialisation de modles
paquets de paramtres (C++11)
Divers
Assembleur
 
Excute conditionnellement code .
Original:
Conditionally executes code.
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 excut que si une certaine condition est prsent .
Original:
Used where code needs to be executed only if 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.

Syntaxe

if ( expression ) statement_true
if ( expression ) statement_true else statement_false

Explication

expression doit tre une expression, convertible en bool .
Original:
expression shall be an expression, convertible to bool.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Si elle est value true, le contrle est pass statement_true, statement_false (si prsent) n'est pas excut .
Original:
If it evaluates to true, control is passed to statement_true, statement_false (if present) is not executed.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Sinon, le contrle est pass statement_false, statement_true n'est pas excut .
Original:
Otherwise, control is passed to statement_false, statement_true is not executed.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Mots-cls

if, else

Exemple

L'exemple suivant illustre l'utilisation de plusieurs cas de la dclaration if
Original:
The following example demonstrates several usage cases of the if statement
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <iostream>

int main()
{
    int i = 2;
    if (i > 2) {
        std::cout << "first is true" << '\n';
    } else {
        std::cout << "first is false" << '\n';
    }
    
    i = 3;
    if (i == 3) std::cout << "i == 3" << '\n';
    
    if (i != 3) std::cout << "i != 3" << '\n';
    else        std::cout << "i != 3 is false" << '\n';
}

Rsultat :

first is false
i == 3
i != 3 is false

Web Proxy Viewer  |  New URL  |  Original Page