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.