🔁 for Loop in C

🔁 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++ or i += 1 for counting up
  • You can use break and continue inside 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.


Keywords: for loop in c, c programming for loop, c loop syntax, for loop example in c, beginner c tutorial loop Tags: c programming, for loop, loops in c, control statement, iteration

একটি মন্তব্য পোস্ট করুন