Used to iterate a specific number of times.
Syntax:
for (initialization; condition; update) {
// Code to be executed in each iteration
}
#include <stdio.h>
int main() {
// Print numbers from 1 to 5 using a for loop
for (int i = 1; i <= 5; i++) {
printf("%d ", i);
}
return 0;
}
See how the loop works
#include <stdio.h>
int main() {
// Iterating through an array
int numbers[] = {10, 20, 30, 40, 50};
for (int i = 0; i < 5; i++) {
printf("%d ", numbers[i]);
}
return 0;
}
Learn more about C arrays
The Concepts and codes you leart practice in Compilers till you are confident of doing on your own. A Various methods of examples, concepts, codes availble in our websites. Don't know where to start Down some code examples are given for this page topic use the code and compiler.