Using the continue statement with a label reference, to skip a value in a nested for loop: - Javascript Statement

Javascript examples for Statement:continue

Description

Using the continue statement with a label reference, to skip a value in a nested for loop:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//from   ww w .  ja  v  a  2  s.c  o m
    var text = "";
    var i, j;

    Loop1:           // The first for loop is labeled "Loop1"
    for (i = 0; i < 3; i++) {
    text += "<br>" + "i = " + i + ", j = ";

        Loop2:           // The second for loop is labeled "Loop2"
        for (j = 10; j < 15; j++) {
            if (j === 12) {
                 continue Loop2;
            }
            document.getElementById("demo").innerHTML = text += j + " ";
        }
    }

}
</script>

</body>
</html>

Related Tutorials