While Loop

while (condition) { }

When you need to repeat an action many times, use a loop.

A while loop looks just like an if statement. But instead of choosing a path, the
while loop repeats its action for as long as the condition stays true.

while (condition) {
  // runs again and again, as long as condition is true
}

Example: Counting Up

let count = 0;
while (count < 5) {
  count = count + 1;
}
// count is now 5

Each time through, count goes up by one. Once count reaches 5, count < 5 is no
longer true, so the loop stops.

You Can Crash Your Computer

while (true) {
  // this never stops
}

true is always true, so this condition never turns false. If nothing inside the loop
changes the condition — or you write while (true) on purpose — the loop runs forever
and can freeze or crash your computer.