0

Possible Duplicate:
Best way to break from nested loops in Javascript?

Is using labels to break loops, a good practice in javascript? Mention if it has any pros and cons

Ex:

var i, j;
outer:
    for(i in [0,1,2,3]) { 
    inner:
        for(j in [0,1,2,3]) { 
            if(j == 1) { 
                break outer; 
            }
        } 
        console.log("inner")
    } 
console.log("outer");
4
  • You should not use for .. in loops for arrays.
    – dfsq
    Feb 6, 2012 at 7:14
  • This is not a duplicate. Feb 6, 2012 at 7:29
  • 1
    @people who closed the question I didn't ask how to exit javascript nested loops. I have asked whether it is a good practice to use labels or not. Take time to read questions before closing them.
    – Tamil
    Feb 6, 2012 at 7:48
  • Check this: marcin-chwedczuk.github.io/…
    – csharpfolk
    Jun 13, 2016 at 9:02

1 Answer 1

0

Yes, it is the best way to break out of multiple loops.

Not the answer you're looking for? Browse other questions tagged or ask your own question.