Infinite Loop

noun

say it: “IN-fih-nit LOOP” /ˈɪnfɪnɪt luːp/

A loop whose condition never becomes false, so it repeats forever and the program never moves on.

What is Infinite Loop in JavaScript?

Infinite Loop — A loop whose condition never becomes false, so it repeats forever: the program hangs, or the page freezes. It usually means the loop forgot to change the variable its condition checks. In the terminal, Ctrl+C stops it.

let bikesLeft = 3;
while (bikesLeft > 0) {
  console.log(`Bikes left: ${bikesLeft}`); // 3, then 2, then 1
  bikesLeft--; // without this line, the loop never ends
}

In a sentence

  • “I forgot to add 1 to count, so my infinite loop printed the same line until I pressed Ctrl+C.”

Level: Novice · More JavaScript terms at this level

Updated

In other subjects