Using labels in javascript for loop - Javascript Statement

Javascript examples for Statement:for

Introduction

Normally, break only breaks the immediate loop. This one breaks the loop labelled as dance.

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {// w  ww. j  a  v a  2 s.  c om
var i, j;
dance: for (i = 0; i < 20; i++) {
    for (j = 0; j < 20; j++) {
        console.log(i+'-'+j);
        if (j === 10) { 
            break dance; 
        }
    }
}
    });

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials