名前空間
変種
操作

for loop

提供: cppreference.com
< c‎ | language

ループを実行.
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.
のより読み相当として使用.

目次

[編集] 構文

for ( init_expression ; cond_expression ; iteration_expression ) loop_statement

[編集] 説明

上記の構文に相当するコードを生成します
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 ;
}

}

init_expressionは、ループの実行前に実行されます。 cond_expressionboolに変換、値に評価しなければならない。これは、ループの各反復の前に評価されます。ループは、その値がtrueある場合にのみ続行されます。 loop_statementiteration_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.
は文の終端として使用することができます.
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.
はショートカットとして使用することができます.
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.

[編集] キーワード

for

[編集]

次の例では、配列操作のループ " 'の使用方法を示します
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;
}

出力:

Array filled!
1 0 1 1 1 1 0 0