pav
5/18/2013 - 2:14 PM

Let's say we have a loop and there's some condition that makes us want to immediately stop the loop. There's a handy statement called break

Let's say we have a loop and there's some condition that makes us want to immediately stop the loop.

There's a handy statement called break that lets us do just that. It works for both for and while loops, but not for recursion.

It's similar to return (which lets you end a function), but is specifically for loops only.

while (true) {
    console.log("I only print once!");
    break;
}