The for loop is usually used when the number of iterations is predetermined.
The format of the for loop is
for (expr1;expr2;expr3){
s1;
s2 ;
}
expr1 is executed only once before looping.
expr2 is a Boolean expression. If not given, it is assumed to be true.
If expr2 is false, the loop is terminated.
After execution of the repeat section, expr3 is executed
The expressions expr1, expr2 and expr3 are all optional.
#include
main(){
int i,n = 5;
for(i = 0; i < n; i = i+1){
printf("the numbers are %d \n",i);
}
}
the numbers are 0
the numbers are 1
the numbers are 2
the numbers are 3
the numbers are 4