If you're learning to code or enrolled in a C Programming Course in Noida, one of the first control structures you'll come across is the for loop. It's simple in structure but incredibly powerful when used correctly. Whether you're printing numbers, handling arrays, or solving logic problems, the for loop is a fundamental concept that every C programmer must master.
In this article, we’ll walk you through the complete syntax of a for loop, explain how it works, and provide practical for loop in C programming examples that you can experiment with as a beginner.


A for loop is a control structure used in C that allows code to be executed repeatedly based on a condition. It is best used when the number of iterations is known beforehand.
The basic idea is simple: "Repeat a block of code a specific number of times."
Here is the general syntax of a for loop in C:
for (initialization; condition; increment/decrement) {
// Code to be executed
}
This control flow mechanism is both compact and powerful, making it ideal for scenarios where you need controlled repetition.
Here's a basic for loop in C programming exampleto print numbers from 1 to 5:
#includeint main() { for (int i = 1; i <= 5; i++) { printf("%d\n", i); } return 0; < pre>
1
2
3
4
5
This loop starts at i = 1, checks whether i<= 1 5, and then increments i by after each iteration.< p>
For loops are ideal for working with arrays. Here's an example of printing the elements of an array:
#includeint main() { int numbers[] = {10, 20, 30, 40, 50}; int length = sizeof(numbers) / sizeof(numbers[0]); for (int i = 0; i < length; i++) { printf("Element %d: %d\n", i, numbers[i]); } return 0; }
This loop goes through each index of the array and prints its value, demonstrating one of the most common uses of the for loop.
You can also use one for loop inside another. This is known as a nested for loop, and it's often used for pattern printing and matrix operations.
#includeint main() { for (int row = 1; row <= 3; row++) { for (int col="1;" <="3;" col++) printf("%d ", col); } printf("\n"); return 0; pre>
1 2 3
1 2 3
1 2 3
Nested loops are invaluable for dealing with multi-dimensional data structures.
If you forget to update the condition or intentionally leave it always true, you can create an infinite loop.
for (;;) {
// This will run forever unless broken manually
}
This type of loop is usually used in system-level programming or when the program is meant to run continuously until a specific condition is met (using a break statement inside the loop).
To exit the loop when a certain condition is met.
for (int i = 1; i <= 10; i++) { if (i="=" 5) break; printf("%d\n", i); } < pre>
1
2
3
4
To skip the current iteration and jump to the next one.
for (int i = 1; i <= 5; i++) { if (i="=" 3) continue; printf("%d\n", i); } < pre>
1
2
3
4
5
Control statements give you more flexibility and precision within your loops.
| Feature | For Loop | While Loop | Do-While Loop |
|---|---|---|---|
| Initialization | Done in loop header | Done before loop | Done before loop |
| Condition Check | At the start | At the start | At the end |
| Use Case | Known number of iterations | Unknown iterations | Run at least once |
In most C Programming Courses in Noida, the for loop is introduced before other loop types because of its clear and concise syntax.
Following best practices ensures your loops are not only functional but also maintainable.
A structured C Programming Course in Noidawill typically help beginners avoid these mistakes through exercises and mentorship.
for (int i = 2; i <= 20; i +="2)" { printf("%d ", i); } < pre>
int num = 5;
for (int i = 1; i <= 10; i++) { printf("%d x %d='%d\n",' num, i, num * i); } < pre>
for (int i = 10; i >= 1; i--) {
printf("%d ", i);
}
Adding these examples to your toolkit prepares you for more complex logic.
#includeint main() { int num, fact = 1; printf("Enter a positive integer: "); scanf("%d", &num); for (int i = 1; i <= num; i++) { fact *="i;" } printf("factorial of %d='%d\n",' num, fact); return 0; < pre>
This is a great for loop in C programming example to understand multiplication through iteration.
The for loop is a foundational part of C programming and is widely used in real-world applications. It simplifies iteration, makes code more readable, and gives precise control over how many times a block of code runs.
Whether you’re just starting out or polishing your coding skills through a C Programming Course in Noida, mastering the for loop is essential. Practice various examples, experiment with nested loops, and try using different conditions to strengthen your logic and confidence.
If you’re serious about learning C in a structured, project-based environment, a dedicated programming course can make all the difference.
Personalized learning paths with interactive materials and progress tracking for optimal learning experience.
Explore LMSCreate professional, ATS-optimized resumes tailored for tech roles with intelligent suggestions.
Build ResumeDetailed analysis of how your resume performs in Applicant Tracking Systems with actionable insights.
Check ResumeAI analyzes your code for efficiency, best practices, and bugs with instant feedback.
Try Code ReviewPractice coding in 20+ languages with our cloud-based compiler that works on any device.
Start Coding
TRENDING
BESTSELLER
BESTSELLER
TRENDING
HOT
BESTSELLER
HOT
BESTSELLER
BESTSELLER
HOT
POPULAR