The for loop:
The
for loop is another form of looping statement which is the most versatile,
convenient and popular of the three loop structure available in C. It is used
in those situations when the programmer knows in advance the number of times a
statement or statement block will be executed. In this loop, the loop control
elements are gathered in one place, while in other loops they are scattered
over the program and difficult to understand. The for allows us to specify
three things about a loop in a single line:
1.
An expression that specifies an initial value for loop
counter. For example: i=0;.
2.
A testing expression that determine whether the loop counter
has reached the number of repetitions desired by the condition. For example:
i < 5; i >= 5; i< = 6;
3.
A third condition that allows the loop counter to be modified
at the end of each pass.
General Syntax:
for ( initialize counter ; test counter ;
increment counter )
{
body of loop;
}
For Example:
for ( i=0 ; i < 10 ; i++)
{
printf ( “\n Hello”);
}
Post a Comment