For loop in C Programming
In the C programming language, the for loop is used to repeatedly iterate over a set of instructions or a section of code. It is frequently used to traverse array-based and linked list-based data structures.
Instead of using a while and do-while loop, the for loop provides better results.
Syntax of For Loop
for (initialize Statement; Conditional Function; Increment Expression)
{
// Statements inside of the loop's body //
}
Working process in for loop
- One single initialization assertion is made at a time.
- The check expression is then assessed. The for loop is ended if the check expression is interpreted as false.
- However, statements inside the for loop's frame are carried out, and the update expression is updated. On the other hand, if the check expression is evaluated as true, statements inside the for loop's frame are carried out, and the update expression is changed.
- The check expression is tested once again.
Flowchart of for loop in C
The below Flowchart of For loop representing a way to find the factorial of a number.

Algorithm for the above flow chart:
Step 1: Start.
Step 2: Initialization of the variables.
Step 3: Checking for condition.
Step 4: If the condition returns to be true, go to step 5; otherwise, go to step 7.
Step 5: f = f * i.
Step 6: Go to step 3.
Step 7: Print the factorial value.
Step 8: Stop.
For loop Examples in C
1. Program to Print Numbers from 1 to 10
// Printing numbers from 1 to 10 //
#include <stdio.h>
int main()
{
// Initializing integer variable //
int i;
for (i = 1; i < 11; ++i)
{
printf(" %d ", i);
}
return 0;
}
OUTPUT

2. C Program: Print table for the given number using C for loop
#include<stdio.h>
int main()
{
// Initialize the integer values //
int i=1, n=0;
printf( " Enter a integer value : ");
scanf("%d",&n);
for(i=1;i<=10;i++)
{
printf(" %d \n ",(n*i));
}
return 0;
}
OUTPUT

Characteristics of initialize Statement:
- The initialize Statement represents the initialization of the loop variable.
- In the initialization Statement, we can initialize a couple of variables.
- Initialize Statement is not required.
- Initialize Statement's variables cannot be declared in C. In certain compilers, it could be an exception, though.
3. // Program to show that multiple statements can be initialized at once //
#include <stdio.h>
int main()
{
// initializing integer variables //
int a, b, c;
// multiple integer values are initialized at once //
for(a=0,b=24,c=23; a<8; a++)
{
printf( "%d " , a+b+c);
}
return 0;
}
OUTPUT

Characteristics of Condition Statement:
- A conditional Statement checks to see whether a chosen condition is true. In the absence of true conditions, the loop is ended.
- Condition Statements will be subjected to many conditions. The loop will continue iterating until the final condition is met. Alternative circumstances could be treated as statements.
- Condition Statement is not necessary.
- The Initialization statement and the Updation statement can be replaced with expression 2, which can complete their tasks. That is, in addition to replacing the loop variable in expression 2 itself, we can initialize the variable.
- In expression 2, we will disregard zero or non-zero values. In C, however, a non-zero number is true by default, while a zero is false.
4. // Program to show that multiple conditional statements can be given at once //
#include <stdio.h>
int main()
{
// initializing integer variables //
int i, j, k;
for(i=0, j=0, k=0; i<5, k<7, j<19; i++)
{
// printing the values //
printf(" %d %d %d \n " , i,j,k);
j+=2;
k+=3;
}
return 0;
}
OUTPUT

Characteristics of Increment Expression
- The loop variable is changed using the Increment Expression.
- More than a single variable can be updated at once.
- Increment Expression is not compulsory.
5. // Program for Increment expression //
#include<stdio.h>
void main ()
{
// Declaring the Integer variables //
int i=0, j=2;
for(i = 0; i<5; i++, j=j+2)
{
// Printing the Integer variables //
printf(" %d %d \n " , i,j);
}
return 0;
}
OUTPUT

Advantages of For Loop
- It is possible to initialize within or outside of a loop statement.
- After the Statement (s) are executed, the increment is carried out.
- It is commonly used when the number of iterations is known.
- It is used when easy initialization and increment are possible.
- The for loop is an entry-controlled loop.
- Used to reach the desired outcome is most successful when the variety of iterations is known.