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 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Uso
- for bucle: como la declaración del bucle
|
(desde C++11) |
Ejemplo
Ejecutar este código
#include <iostream> int main() noexcept { // La siguiente sentencia 'for': // 1. (init-statement) Declara un entero llamado 'i' y lo inicializa con el valor '0'. // 2. (condition) Comprueba si i es menor que 3 y si no, finaliza la ejecución del bucle. // 3. (statement) Escribe el valor actual del entero 'i' en stdout. // 4. (expression) Pre-incrementa el entero 'i' (incrementa su valor en 1). // 5. Regresa al punto 2 (condition). // init-statement: int i{0}; // condition: i < 3 for (int i{0}; i < 3; ++i) // expression: ++i std::cout << i; // statement: std::cout << i; }
Salida:
012
Véase también
|
(desde C++17) |
|
(desde C++23) |
-
switch
sentencia:
switch,case -
default
(como declaración de etiqueta case)
etc:
default -
goto
sentencia:
goto -
continue
sentencia:
continue -
break
sentencia:
break -
return
sentencia:
return
| (desde C++20) |
-
do-while
bucle y
whilebucle :do,while