Espaces de noms
Variantes
Affichages
Actions

for loop

De cppreference.com
< c‎ | language

 
 
Langage C
Les sujets généraux
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
Commentaires
Mots-clés
Table ASCII
Séquences d'échappement
Histoire de C
Le contrôle de flux
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.
États d'exécution conditionnelles
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.
Des instructions d'itération
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
Aller déclarations
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.
Fonctions
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
déclaration de la fonction
spécificateur inline
Types
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Les prescripteurs
Original:
Specifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
prescripteurs cv
classe de stockage prescripteurs
alignas spécificateur (C99)
Littéraux
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Expressions
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
ordre d'évaluation
les opérateurs alternatifs
opérateurs
la priorité des opérateurs
Utilitaires
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
attributs (C99)
jette
Divers
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Assembleur inline
 
Exécute une boucle .
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.
.

Sommaire

[modifier] Syntaxe

for ( init_expression ; cond_expression ; iteration_expression ) loop_statement

[modifier] Explication

La syntaxe ci-dessus produit code équivalent à:
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 ;
}

}

La init_expression est exécutée avant l'exécution de la boucle. Le cond_expression doit évaluer à la valeur convertible en bool. Il est évaluée avant chaque itération de la boucle. La boucle continue seulement si sa valeur est true. La loop_statement est exécuté à chaque itération, après quoi iteration_expression est exécutée .
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.
peut être utilisé comme terminaison déclaration .
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.
peut être utilisé comme raccourci .
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.

[modifier] Mots-clés

for

[modifier] Exemple

L'exemple suivant illustre l'utilisation de la 'pour' en boucle dans une manipulation des tableaux
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;
}

Résultat :

Array filled!
1 0 1 1 1 1 0 0