Start Loop
1. Start:let i = 0(Start at 0)
2. Check:i < 5(0 is less than 5)
3. Next:i++(Add 1 to i)
1i = 0
2i = 1
3i = 2
4i = 3
5i = 4

Loop runs 5 times. Current i: 0

for (let i = 0; i < 5; i++) {
    console.log(i + 1);
}

For Loop

The classic loop. 'for (let i = 0; i < 5; i++)' breaks down to: 1. Start at 0. 2. Stop if i is 5 or more. 3. Add 1 to i after each round.

For Loop: Use Case

When should you use it? Think 'Bulk Actions'. Perfect for when you have a list of items (like emails) and need to process each one.

While Loop

Keep going AS LONG AS a condition is true. 'While the tank has gas, keep driving.' Careful: if the condition never becomes false, you get an INFINITE loop!

While Loop: Use Case

Think 'Game Loop'. You don't know when the game ends, so you just keep checking 'isAlive' until it's false.

Do-While Loop

Similar to 'While', but guaranteed to run at least ONCE. 'Roll the dice. Keep rolling UNTIL you get a 6.'

Do-While Loop: Use Case

Think 'Password Retry'. You MUST ask for the password at least once before you check if it's correct.

Loop Master

You can now make your code work harder, not smarter.
Time to organize code into reusable blocks called Functions.

AlgoAnimator: Interactive Data Structures