Master counting loops
A for loop is perfect when you know exactly how many times you want to repeat something. It's like counting from 1 to 10!
For Loop Structure:
A for loop has three parts: initialization, condition, and update. All in one line!
for (let i = 0; i < 5; i++) {
console.log("Count: " + i)
}
// Output: Count: 0, Count: 1, Count: 2, Count: 3, Count: 4Initialization: let i = 0
Sets up the counter variable (runs once at the start)
Condition: i < 5
Checks before each loop (if false, loop stops)
Update: i++
Runs after each loop iteration
Why use 'i'?
By tradition, programmers use 'i' as the counter variable (it stands for "index"). You can use any name, but 'i' is the most common!