C for Loops
The for statement has three expressions, semicolon are used for separating these expressions. so the syntax of statement is
{
statement
statement
………
………
………
}
|
In the for loop body statement can be single or group of statements
In this above example Expression1 is initialization expression, expression2 is condition expression and in the last expression3 is an update expression. in the for loop, expression1 is executed only once when the loop start then initialize the loop variables. This expression is know as initialize or assignment expression because its initialize the value.expression2 is condition and its tested or check condition at every iteration of the loop, so this condition expression generally uses logical and relational operators. At the end expression3 is an update expression and its execute every time after execute the body of the loop.
/* program to understand the concept of for loop*/
main()
{
i;
{
printf("C program");
}
0;
}
|
/* program to print 1 to 100 number using for loop*/
main()
{
i;
{
printf("%d",i);
}
0;
}
|