Espacios de nombres
Variantes
Acciones

for loop

De cppreference.com
< c‎ | language

 
 
Lenguaje C
Los temas generales
Original:
General topics
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Preprocessor
Comentarios
Palabras clave
Tabla ASCII
Las secuencias de escape
Historia de C
Control de flujo
Original:
Flow control
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Sentencias condicionales ejecución
Original:
Conditional execution statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Instrucciones de iteración
Original:
Iteration statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
for loop
Ir declaraciones
Original:
Jump statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Funciones
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
declaración de la función
especificador inline
Tipos
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Los especificadores
Original:
Specifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
cv especificadores
especificadores de clase de almacenamiento
alignas especificador (C99)
Los literales
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Expresiones
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
orden de evaluación
los operadores alternativos
los operadores
prioridad de los operadores
Utilidades
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
typedef declaration
atributos (C99)
proyecta
Varios
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Montaje en línea
 
Ejecuta un bucle .
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.
.

Contenido

[editar] Sintaxis

for ( init_expression ; cond_expression ; iteration_expression ) loop_statement

[editar] Explicación

La sintaxis anterior produce código equivalente a:
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.
{
init_expression ;
while ( cond_exression ) {
loop_statement
iteration_expression ;
}

}

El init_expression se ejecuta antes de la ejecución del bucle. El cond_expression evaluará a valorar, convertible a bool. Se evalúa antes de cada iteración del bucle. El bucle continúa sólo si su valor es true. El loop_statement se ejecuta en cada iteración, después de lo cual se ejecuta iteration_expression .
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.
se puede utilizar como la terminación de declaración .
Original:
If the execution of the loop needs to be terminated at some point,
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
se puede utilizar como acceso directo .
Original:
If the execution of the loop needs to be continued at the end of the loop body,
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Palabras clave

for

[editar] Ejemplo

El siguiente ejemplo demuestra el uso de la 'de' bucle en una manipulación de matrices
Original:
The following example demonstrates the usage of the for loop in an array manipulation
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <stdio.h>
#include <stdlib.h>
 
#define SIZE 8
 
int main (int argc, char **argv)
{
    unsigned i = 0, array [SIZE];
 
    for( ; i < SIZE; ++i)
        array [i] = random() % 2;
 
    printf("Array filled!\n");
 
    for (i = 0; i < SIZE; ++i)
        printf("%d ", array[i]);
 
    printf("\n");
 
    return EXIT_SUCCESS;
}

Output:

Array filled!
1 0 1 1 1 1 0 0