for loop – cppreference.com
Aus cppreference.com
<metanoindex/>
Führt eine Schleife .
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.
Syntax
for ( init_expression ; cond_expression ; iteration_expression ) loop_statement
|
|||||||||
Erklärung
Die obige Syntax erzeugt Code äquivalent zu:
Original:
The above syntax produces code equivalent to:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
{
|
|||||||||
Die init_expression wird vor der Ausführung der Schleife ausgeführt. Die cond_expression wird auf den Wert zu beurteilen, umwandelbar in bool. Es wird vor jeder Iteration der Schleife ausgewertet. Die Schleife wird nur, wenn ihr Wert true ist. Die loop_statement auf jeder Iteration ausgeführt, wonach iteration_expression ausgeführt wird .
Original:
The init_expression is executed before the execution of the loop. The cond_expression shall evaluate to value, convertible to bool. It is evaluated before each iteration of the loop. The loop continues only if its value is true. The loop_statement is executed on each iteration, after which iteration_expression is executed.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Keywords
Beispiel
#include <iostream> int main() { for (int i = 0; i < 10; i++) { std::cout << i << " "; } std::cout << '\n'; for (int j = 2; j < 9; j = j + 2) { std::cout << j << " "; } }
Output:
0 1 2 3 4 5 6 7 8 9 2 4 6 8