Syntax of a for loop in C?
In C, the for loop is used to repeat a block of instructions several times. It has three parameters:
- an initialization which is usually used to assign a value to a variable;
- a condition which is a test that will determine when the loop should stop;
- an iteration which is an operation that specifies the step of the loop.
Syntax:
for (initialization ; test ; iteration)
{
// Repeated code
}
Flowchart:
Example :
for (i=0 ; i<10 ; i++)
{
printf ("%d\n", i);
}
Try online on repl.it.
The parameters of the loop are optional. The following code is an infinite loop, equivalent to while(1);
:
for (;;);
See also:
In C, the for loop is used to repeat a block of instructions several times. It has three parameters:
- an initialization which is usually used to assign a value to a variable;
- a condition which is a test that will determine when the loop should stop;
- an iteration which is an operation that specifies the step of the loop.
Syntax:
for (initialization ; test ; iteration)
{
// Repeated code
}
Flowchart:
Example :
for (i=0 ; i<10 ; i++)
{
printf ("%d\n", i);
}
Try online on repl.it.
The parameters of the loop are optional. The following code is an infinite loop, equivalent to while(1);
:
for (;;);
See also:
In C, the for loop is used to repeat a block of instructions several times. It has three parameters:
- an initialization which is usually used to assign a value to a variable;
- a condition which is a test that will determine when the loop should stop;
- an iteration which is an operation that specifies the step of the loop.
Syntax:
for (initialization ; test ; iteration)
{
// Repeated code
}
Flowchart:
Example :
for (i=0 ; i<10 ; i++)
{
printf ("%d\n", i);
}
Try online on repl.it.
The parameters of the loop are optional. The following code is an infinite loop, equivalent to while(1);
:
for (;;);
See also:
# | ID | Query | URL | Count |
---|