代码示例:(标识:jsck_state_for_nested)
<!DOCTYPE html>
<html>
<body>

<p>在这个例子中,我们有两个循环。因为有一个循环在另一个循环内,所以我们称其为嵌套循环。第一个循环通常称为“外循环”,第二个循环通常称为“内循环”,因为它位于第一个外循环内。</p>

<p>外循环先执行,每执行一次外循环,内循环也将执行。</p>

<button onclick="myFunction()">试一试</button>

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

<script>
function myFunction() {
  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>
运行结果: