C Tutorial · Chapter 13 of 16
C For Loop
Repeat when the count is known.
for (start; condition; update) is ideal for counting and array scans.
Nested for loops are used for tables and patterns.
For sample
Try it Yourself »
#include <stdio.h>
int main(void) {
for (int i = 1; i <= 5; i++) {
printf("%d\n", i);
}
return 0;
}
Classroom Tips
- Off-by-one errors often come from <= versus <.