for Loop Statement

There are three parts which is separated by semi-colons in control block of the for loop.
initialization_expression is executed before execution of the loop starts. This is typically used to initialize a counter for the number of loop iterations. You can initialize a counter for the loop in this part.
The execution of the loop continues until the loop_condition is false. This expression is checked at the beginning of each loop iteration.
The increment_expression, is usually used to increment the loop counter. This is executed at the end of each loop iteration.
Here is an example of using for loop statement to print an integer five times

#include <stdio.h>

void main(){
// using for loop statement
int max = 5;
int i = 0;
for(i = 0; i < max;i++){

printf("%d\n",i);

}
}

No comments:

Post a Comment