```c for (int i = 0; i < 5; ++i) { printf("%d\n", i); } ``` This prints five lines, using `i` as 0, 1, 2, 3, and 4. A `for` loop repeats its body while its condition remains true, combining initialization, continuation, and update in one construct. section 2.4.1
Read `for (clause1; condition2; expression3) statement-or-block` in execution order:
- Initialize the loop variable once before the first body execution; normally define it in the initial clause so its scope stays narrow. section 2.4.1 section 3.2
- Check the condition before every body execution; a false value stops the loop. section 2.4.1 section 3.4
- Execute the body, then evaluate the update expression, such as `++i`, before checking the condition again. section 2.4.1 section 3.2
- Use `for` for domain iteration; use `while` or `do` when their condition placement better matches the task. section 2.4.1 section 3.2
for (clause1; condition2; expression3) statement-or-block
!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":3},{\"line\":0,\"ch\":6}],[{\"line\":0,\"ch\":4},{\"line\":0,\"ch\":6}]]"}
!@%STYLE%@!
Use the formal pattern to distinguish the initialization clause, continuation condition, update expression, and repeated statement or block. section 3.2
Counting, bounds, and termination
These loops show common variations: ```c for (size_t i = 10; i; --i) { something(i); } for (size_t i = 0, stop = upper_bound(); i < stop; ++i) { something_else(i); } ``` The first counts down while `i` is nonzero. The second keeps the stopping bound in a separate variable. A loop can also omit clauses, as in `for (;;)`, and terminate explicitly with `break`; `continue` skips to the next iteration. section 3.2


























