C for Loop
In C programming, loops are responsible for performing repetitive tasks using a short code block that executes until the condition holds true. In this article, we will learn one such loop for loop.
What is for loop in C Programming?
For Loop in C Language provides a functionality/feature to recall a set of conditions for a defined number of times, moreover, this methodology of calling checked conditions automatically is known as for loop.
for loop is in itself a form of an entry-controlled loop. It is mainly used to traverse arrays, vectors, and other data structures.

Syntax of for loop in C
for(initialization; check/test expression; updation)
{
// body consisting of multiple statements
}Structure of for Loop in C
for loop follows a very structured approach where it begins with initializing a condition then checks the condition and in the end executes conditional statements followed by an updation of values.
- Initialization: This is the first parameter of a fundamental for loop that accepts a conditional variable that iterates the value or helps in checking the condition.
- Conditional Statement: It accepts 3 parameters(Initialization, Condition, and Updation) that indicate what condition needs to be followed and checked.
- Check/Test Condition: The Second parameter of a fundamental for loop defines the condition that needs to be followed to run the following code statements. In simple terms, if the check expression is true then the iteration of the loop continues otherwise the loop is terminated and further checks(if possible/there) are left unchecked.
- Updation: The Third parameter of a fundamental for loop defines the incrementation or decrementation of the conditional variable that will iterate the code according to the condition.
- Body: It is termed as the collection of statements i.e. variables, functions, etc. These are executed automatically after a successful iteration that executes with every successful iteration cycle until the condition is not satisfied. The code statements within the for loop could be anything from printing a simple name to executing complex algorithms or functional statements.
How C for Loop Work?
The working of for loop is mentioned below:
- Step 1: Initialization is the basic step of for loop this step occurs only once during the start of the loop. During Initialization, variables are declared or already existing variables are assigned some value.
- Step 2: During the Second Step condition statements are checked and only if the condition is the satisfied loop we can further process otherwise loop is broken.
- Step 3: All the statements inside the loop are executed.
- Step 4: Updating the values of variables has been done as defined in the loop.
- Continue to Step 2 till the loop breaks.
Flowchart of for Loop in C

Flowchart of for loop
for loop examples in C
C
// C program to demonstrate for loop#include <stdio.h> int main(){ int gfg = 0; // 'gfg' <= 5 is the check/test expression // The loop will function if and only if 'gfg' is less // than 5 //'gfg++' will increments it's value by this so that the // loop can iterate for further evaluation // conditional statement for (gfg = 1; gfg <= 5; gfg++) { // statement will be printed printf("GeeksforGeeks\n"); } // Return statement to tell that everything executed // safely return 0;} |
GeeksforGeeks GeeksforGeeks GeeksforGeeks GeeksforGeeks GeeksforGeeks
Nested for loop in C
C provides the feature of a nested loop where we can place a loop inside another loop.
Syntax:
for( .. ; .. ; .. ){
for( .. ; .. ; .. ){
....
}
}To know more about nested for loop refer to Nested for loop in C.
Special Conditions:
1. for loop without curly braces:
You already know about for loop and its syntax, when we declare a for loop without curly braces, the loop executes only one statement which is written just after it, and the statement can not be declarative.
Example:
C
#include <stdio.h> int main(){ int i; // for loop without curly braces for (i = 1; i <= 10; i++) printf("%d ", i); printf("\nThis statement executes after for loop end!!!!"); // Statement print only once return 0;} |
1 2 3 4 5 6 7 8 9 10 This statement executes after for loop end!!!!
2. Infinite for Loop/NULL Parameter Loop:
This is also a kind of for loop where the input parameters are not available or do not exist by virtue of which the loop iterates/runs endlessly.
Example:
C
// C program to demonstrate infinite Loop#include <stdio.h> int main(){ int gfg = 0; for (;;) // condition 1,2 and 3 are not entered { printf("GeeksforGeeks to Infinite"); } // Return statement to tell that everything executed // safely return 0;} |
Output:
GeeksforGeeks to InfiniteGeeksforGeeks to InfiniteGeeksforGeeks to InfiniteGeeksforGeeks to InfiniteGeeksforGeeks to Infinite.....
Advantages and Disadvantages of for Loop in C
Advantages of for loop:
There are certain advantages of using for loops in C as mentioned below:
- Provides code reusability
- Code size decreases
- Traversing in data structures like array and string becomes easy.
Disadvantages of for loop:
Despite so many advantages of for loops it even has certain disadvantages:
- Can’t skip any element while traversing
- Only a single condition is followed
Conclusion
In this article, the points we learned about for loops are mentioned below:
- It is an Entry-Controlled Loop
- It can iterate from an adequate number to an infinite number according to the situation.
- It requires 3 conditions parameters i.e. check expression, conditional statement, and urinary operators for updation.
- Its workflow is an initialization, check/test, and then updation.
FAQs on for loops in C
1. What is a loop?
The repetition of statements multiple times in a particular order is defined as a loop.
2. How to do iteration in C programming?
Iteration can be performed using a loop in C programming, where we print or run statements on every element of the structure till every element is traversed.
3. How many types of looping statements are there in C Programming?
There are three types of looping statements in C Programming as mentioned below:
- Goto statement
- Continue statement
- Break statement
4. Can we use multiple variables in for loop?
Yes, we can use multiple variables in for loop.
5. How to make an infinite for loop in c?
We can make a loop infinite for a loop by just defining a condition that is always true for all conditions. Also, no condition defined is treated as an always true condition.



Please Login to comment...