Varianti

for loop

Da cppreference.com.

<metanoindex/>

 
 
Linguaggio C
Temi generali
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.
Preprocessore
Commenti
Parole chiave
Tabella ASCII
Sequenze di escape
Storia di C
Controllo del flusso
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.
Dichiarazioni esecuzione condizionale
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.
Iterazione dichiarazioni
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.
Vai dichiarazioni
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.
Funzioni
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
dichiarazione di funzione
specificatore inline
Tipi
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Specifiers
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 specificatori
della classe di archiviazione specificatori
alignas specificatore (C99)
Letterali
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Espressioni
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
ordine di valutazione
operatori alternativi
operatori
precedenza degli operatori
Utilities
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
attributi (C99)
getta
Varie
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Montaggio in linea
 
Esegue un ciclo.
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.

Sintassi

for ( init_expression ; cond_expression ; iteration_expression ) loop_statement

Spiegazione

La sintassi di cui sopra produce codice 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 ;
}

}

Il init_expression viene eseguito prima dell'esecuzione del ciclo. Il cond_expression valuta al valore, trasformabile in bool. Viene valutata prima di ogni iterazione del ciclo. Il ciclo continua solo se il suo valore è true. Il loop_statement viene eseguito ad ogni iterazione, dopo di che viene eseguito 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.

Parole chiave

for

Esempio

Nell'esempio riportato di seguito viene illustrato l'utilizzo del 'di' loop in una gestione di array
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