Most loops count: from 1 to n, over every item, a fixed number of times. The for loop gathers the three parts of a counting loop (start, test, step) into one line, which makes such loops easy to read and hard to get wrong.
Syntax and order of execution
Syntax
for (initialisation; condition; update) { body}
The for loop executes its parts in this order:
Initialisation: runs once, before anything else.
Condition: tested before every repetition; if false, the loop ends.
Body: runs when the condition is true.
Update: runs after the body; then control returns to step 2.
Equivalent while loop
initialisation;while (condition) { body update;}
Optional parts
Any of the three parts may be left empty, but both semicolons must stay:
Form
Meaning
for (; i <= n; i++)
No initialisation: i is set before the loop
for (i = 1; i <= n; )
No update: i changes inside the body
for (i = 1; ; i++)
No condition: treated as always true; the body must break
for (;;)
Infinite loop; exits only by break, return or goto
Several variables can be initialised or updated using the comma operator: for (i = 0, j = n; i < j; i++, j--). Since C99, the loop variable can be declared in the loop itself: for (int i = 0; i < n; i++); it then exists only inside the loop.
Choosing a loop
Situation
Best loop
The number of repetitions is known (1 to n, 10 times)
for
Repeat until something happens; may be zero times (read until 0)
while
Must run at least once (menu, input validation)
do–while
All three can express any loop; the choice is about clarity.
Key takeaways
for (init; condition; update) puts all the counting logic in one line.
Order: init once, then condition → body → update, repeated.
Any part may be empty; for (;;) is an infinite loop.
Use for for counted loops, while for condition-driven loops, do–while when the body must run once.
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Rewrite for (i = 10; i >= 1; i--) printf("%d ", i); as a while loop and state what it prints.
Show worked answer
i = 10; while (i >= 1) { printf("%d ", i); i--; }. The initialisation moves before the loop, the condition stays in the while, and the update becomes the last statement of the body. It prints 10 9 8 7 6 5 4 3 2 1 (each number followed by a space).
MCA Online notes are made for reading on screen. Open https://mcastudy.online/mcs-201/decision-and-loop-control-statements/the-for-loop/ to read this page.