1

A less well-known feature of JavaScript is that you can use labels to break and continue out of nested loop and switch statements:

i_loop: for (i = 0; i < 10; i++) {
    j_loop: for (j = 0; j < 10; j++) {
        if (i == 3 && i < j)
            break i_loop;
    }
}

This feature is the answer to:

My question is, how portable is it? The MSDN documentation has a long list of supported IE versions. The Mozilla documentation says it was implemented in JavaScript 1.2 (released in 1997), and that it is in ECMA-262, 3rd Edition (1999). Going by this, labels should be extremely portable, but can I count on it?

Community
  • 1
  • 1
Joey Adams
  • 41,996
  • 18
  • 86
  • 115
  • 1
    Why would you think you couldn't count on it? I'd be amazed if you could find a JS implementation that doesn't support it. – nnnnnn Jun 13 '12 at 10:33

1 Answers1

3

According to MDN, a labelled break is supported since the "ECMA-262, Edition 3" standard (published in December 1999, so I believe there should not be a single browser out there that does not support it :))

Alexander Pavlov
  • 31,598
  • 5
  • 67
  • 93