when breaking out of Nested loops in javascript would it be better (as in faster, less problematic, or more popular) to break using a try-catch-throw like a lot of people do in python, or have a self-executing function that returns out of the loops?
Asked
Active
Viewed 577 times
-1
-
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/break – j08691 Jan 22 '14 at 17:13
-
2What's wrong with `break [label];`? – Marc B Jan 22 '14 at 17:13
1 Answers
3
You should use throw
if you encounter a problem that means you cannot continue.
Use return
to indicate you want to exit the function.
Using errors in place of control flow gives the wrong impression about your intent.

Fenton
- 241,084
- 71
- 387
- 401