Introduction
A for loop helps you repeat a set of actions many times without writing the same code again and again.
A for loop helps you repeat a set of actions many times without writing the same code again and again.
for (initialization; condition; update) { // code to repeat }
initialization sets a starting point, like int i = 0;
condition is checked before each loop; if false, the loop stops.
for (int i = 0; i < 5; i++) { printf("%d\n", i); }
for (int i = 10; i > 0; i--) { printf("%d\n", i); }
for (int i = 0; i < 10; i += 2) { printf("%d\n", i); }
This program prints "Hello" followed by numbers 1 to 5, each on a new line.
#include <stdio.h> int main() { for (int i = 1; i <= 5; i++) { printf("Hello %d\n", i); } return 0; }
Remember the semicolons inside the for loop parentheses separate the parts.
If you forget to update the variable, the loop might run forever.
You can use any variable name, not just i.
A for loop repeats code a set number of times.
It has three parts: start, condition, and update.
Use it to count, repeat tasks, or process items step by step.
for loop in C primarily do?for(int i = 1; i <= 3; i++) {
printf("%d ", i);
}for(int i = 0; i < 5; i)
printf("%d ", i);Pass the test and this pattern moves unknown