C++ keyword:
for
From cppreference.net
C++
C++ language
| General topics | ||||||||||||||||
| Flow control | ||||||||||||||||
| Conditional execution statements | ||||||||||||||||
| Iteration statements (loops) | ||||||||||||||||
|
||||||||||||||||
| Jump statements | ||||||||||||||||
| Functions | ||||||||||||||||
| Function declaration | ||||||||||||||||
| Lambda function expression | ||||||||||||||||
inline
specifier
|
||||||||||||||||
| Dynamic exception specifications ( until C++17* ) | ||||||||||||||||
noexcept
specifier
(C++11)
|
||||||||||||||||
| Exceptions | ||||||||||||||||
| Namespaces | ||||||||||||||||
| Types | ||||||||||||||||
| Specifiers | ||||||||||||||||
|
||||||||||||||||
| Storage duration specifiers | ||||||||||||||||
| Initialization | ||||||||||||||||
| Expressions | ||||||||||||||||
| Alternative representations | ||||||||||||||||
| Literals | ||||||||||||||||
| Boolean - Integer - Floating-point | ||||||||||||||||
| Character - String - nullptr (C++11) | ||||||||||||||||
| User-defined (C++11) | ||||||||||||||||
| Utilities | ||||||||||||||||
| Attributes (C++11) | ||||||||||||||||
| Types | ||||||||||||||||
typedef
declaration
|
||||||||||||||||
| Type alias declaration (C++11) | ||||||||||||||||
| Casts | ||||||||||||||||
| Memory allocation | ||||||||||||||||
| Classes | ||||||||||||||||
| Class-specific function properties | ||||||||||||||||
|
||||||||||||||||
| Special member functions | ||||||||||||||||
|
||||||||||||||||
| Templates | ||||||||||||||||
| Miscellaneous | ||||||||||||||||
Keywords
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Identifiers with special meaning | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Verwendung
- for Schleife: als Deklaration der Schleife
|
(seit C++11) |
Beispiel
Diesen Code ausführen
#include <iostream> int main() noexcept { // Die folgende 'for'-Schleifenanweisung: // 1. (Init-Anweisung) Deklariert einen Integer namens 'i' und initialisiert ihn mit dem Wert '0'. // 2. (Bedingung) Prüft ob i kleiner als 3 ist und beendet andernfalls die Schleifenausführung. // 3. (Anweisung) Gibt den aktuellen Wert des Integers 'i' an die Standardausgabe aus. // 4. (Ausdruck) Erhöht den Integer 'i' durch Prä-Inkrement (erhöht seinen Wert um 1). // 5. Springt zurück zu Punkt 2 (Bedingung). // Init-Anweisung: int i{0}; // Bedingung: i < 3 for (int i{0}; i < 3; ++i) // Ausdruck: ++i std::cout << i; // Anweisung: std::cout << i; }
Ausgabe:
012
Siehe auch
|
(seit C++17) |
|
(seit C++23) |
-
switch
Anweisung:
switch,case -
default
(als Fallbezeichner-Deklaration)
etc:
default -
goto
Anweisung:
goto -
continue
Anweisung:
continue -
break
Anweisung:
break -
return
Anweisung:
return
| (seit C++20) |
-
do-while
Schleife und
whileSchleife :do,while