đ for Loop in C
đ Short Explanation:
The for loop is used in C to repeat a block of code a set number of times. It's compact and best when you know how many times to loop.
✅ Syntax
for (initialization; condition; update) {
// code block to execute
}
đ Example: Print 1 to 5
#include <stdio.h>
int main() {
for (int i = 1; i <= 5; i++) {
printf("%d\\n", i);
}
return 0;
}
đ§ Output: 1 2 3 4 5
đĄ Common Use Cases
- Looping through numbers
- Accessing array elements
- Running fixed iteration tasks (e.g. 100 times)
⚠️ Tips & Best Practices
- Always check loop limits to avoid infinite loops
- Use
i++ori += 1for counting up - You can use
breakandcontinueinside loops
đ Summary
The for loop is a powerful and concise way to repeat tasks in C. Mastering it helps handle loops, arrays, and structured logic efficiently.
āĻোāύ āĻŽāύ্āϤāĻŦ্āϝ āύেāĻ:
āĻāĻāĻি āĻŽāύ্āϤāĻŦ্āϝ āĻĒোāϏ্āĻ āĻāϰুāύ