In C programming, for loop is a more efficient loop structure and is an entry-control loop. The iteration continues until the stated condition becomes false.
It has three computing steps as shown in the syntax below.
- initialization: The first step is the initialization of the variable and is executed only once. And need to end with a semicolon(;).
- condition: Second is condition check, it checks for a boolean expression. If true then enter the block and if false exit the loop. And need to end with a semicolon(;).
- Increment or Decrement: The third one is increment or decrement of the variable for the next iteration. Here, we need to use the semicolon(;).
for loop Flowchart:
Syntax of for loop.
for(initialization; condition; Increment or Decrement)
Example of for loop in C Program.
//execution of for loop
for (num = 5; num <= 10; num++)
printf("The values of num: %d\n", num);
The output of for loop in C programming.
The values of num: 5
The values of num: 6
The values of num: 7
The values of num: 8
The values of num: 9
The values of num: 10