Nearby lessons
46 of 124C - For Loop
For Loop is one of the foundational topics in C programming. This lesson explains The for Loop with complete, runnable code examples, clear step-by-step explanations, and common mistakes to avoid with exam-style MCQs at the end.
The for Loop
The for loop gathers three things in one line: where to start, when to stop, and how to move forward.
In simple words: for puts the whole plan in one line — start, stop, step. Read for (i = 1; i <= 5; i++) as "i starts at 1, keep going while i ≤ 5, add 1 each round".
Example01
The for Loop
Example02
The for Loop
Example03
Program: The classic textbook examples: print even numbers, print a multiplication table, sum of first n numbers.
Example04
📝 Key Takeaways
- while checks first; do-while runs at least once; for gathers start/condition/update.
- for is best when you know the number of iterations.
- break stops the loop; continue skips one round.
- Nested loops: inner loop completes for each outer round.
- Pattern programs = outer loop (rows) + inner loop (columns).
- Never forget the update (i++) — else you get an infinite loop.
🧠 Test Your Knowledge
2 QuestionsProgress: 0 / 2