JavaScript Loops: for, while, do...while Explained

Starting my JavaScript learning journey — sharing what I learn every day. 🚀 📅 JavaScript Learning Journey — Day 8 Today I learned about Loops in JavaScript — a powerful way to repeat tasks efficiently. Loops help us execute the same block of code multiple times without writing it again and again. --- 🔎 1. for Loop (Most Used) for (let i = 1; i <= 5; i++) { console.log(i); } 👉 Output: 1 2 3 4 5 --- 🔎 2. while Loop let i = 1; while (i <= 5) { console.log(i); i++; } --- 🔎 3. do...while Loop let i = 1; do { console.log(i); i++; } while (i <= 5); --- 🧠 When to use what? • "for" → when you know how many times to loop • "while" → when condition-based loop • "do...while" → runs at least once --- 📌 Key Takeaways (Day 8) • Loops reduce repetitive code • "for" loop is most commonly used • Always be careful with infinite loops ⚠️ --- This is Day 8 of my JavaScript learning series. Next, I’ll explore Functions in JavaScript. #JavaScript #WebDevelopment #FrontendDeveloper #LearningInPublic #100DaysOfCode

  • diagram

To view or add a comment, sign in

Explore content categories