A nested loop (a loop inside a loop) - Javascript Statement

Javascript examples for Statement:for

Description

A nested loop (a loop inside a 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() {// w  w w.  j  a va  2  s . c  o  m
    var text = "";
    var i, j;

    for (i = 0; i < 3; i++) {
        text += "<br>" + "i = " + i + ", j = ";

        for (j = 10; j < 15; j++) {
            document.getElementById("demo").innerHTML = text += j + " ";
        }
    }
}
</script>

</body>
</html>

Related Tutorials