if statement
Aus cppreference.com
[] |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
<metanoindex/>
Bedingte Ausfhrung.
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.
You can help to correct and verify the translation. Click here for instructions.
Der Code wird nur ausgefhrt, wenn eine bestimmte Bedingung zutrifft.
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.
You can help to correct and verify the translation. Click here for instructions.
Syntax
if ( expression ) statement_true
|
|||||||||
if ( expression ) statement_true else statement_false
|
|||||||||
Erklrung
expression Ausdruck muss in einen Wahrheitswert
bool konvertierbar sein.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.
You can help to correct and verify the translation. Click here for instructions.
Wird der Ausdruck zu
true ausgewertet, wird die Steuerung an statement_true bergeben, statement_false (falls vorhanden) wird nicht ausgefhrt.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.
You can help to correct and verify the translation. Click here for instructions.
Andernfalls wird die Steuerung an statement_false bergeben und statement_true wird nicht ausgefhrt.
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.
You can help to correct and verify the translation. Click here for instructions.
Keywords
Beispiel
Das folgende Beispiel zeigt mehrere Anwendungsflle des
if Statements
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.
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';
}
Output:
first is false
i == 3
i != 3 is false