CHAPTER 12 / 26
C For Loop
Learn how to repeat a block using the for loop.
01 — Syntax
for (initialization; condition; update) {\n // code\n}02 — Example
#include <stdio.h>
int main() {
for (int i = 1; i <= 5; i++) {
printf("%d ", i);
}
return 0;
}03 — Important Points
- The for loop is useful when the number of iterations is known.
- Keep initialization, condition and update clear.
04 — Common Mistakes
- Using the wrong loop condition.
- Off-by-one errors.
05 — Real-World Use
For loops are common in array processing and counting tasks.
06 — Practice
Create a small program that demonstrates the main idea of C For Loop.