C for Loops

C for Loops

The for statement has three expressions, semicolon are used for separating these expressions. so the syntax of statement is

for(expression1; expression2; expression3)
{
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.

for loop in c

/* program to understand the concept of for loop*/
#include<stdio.h>
int
main()
{
int i;
for(i=0;i<=10;i++)
{
printf("C program");
}
return 0;
}

/* program to print 1 to 100 number using for loop*/
#include<stdio.h>
int main()
{
int i;
for(i=1;i<=100;i++)
{
printf("%d",i);
}
return 0;
}