continue loopco...LOGIN

continue loopcontinue

Continue loop continue

Statement structure:

for(初始条件;判断条件;循环后条件值更新)
{
  if(特殊情况)
  { continue; }
 循环代码
}

In the above loop, when a special situation occurs, this loop will is skipped, and subsequent loops will not be affected. It's like outputting 10 numbers. If the number is 5, it won't be output.

<html>
<head>
    <script>
        var num;
        for(num=1;num<10;num++){
            if (num==5)
            {
                continue;//如果num是5,退出循环。
            }
            document.write("数值"+num+"<br />");
        }
    </script>
</head>
<body>
</body>
</html>

The results are as follows:

QQ截图20161012134926.png

In the above code, the loop with num=5 will be skipped.

<!DOCTYPE html>
<html>
<body>
<p>点击下面的按钮来执行循环,该循环会跳过 i=3 的步进。</p>
<button onclick="myFunction()">点击这里</button>
<p id="demo"></p>
<script>
function myFunction()
{
var x="",i=0;
for (i=0;i<10;i++)
  {
  if (i==3)
    {
    continue;
    }
  x=x + "The number is " + i + "<br>";
  }
document.getElementById("demo").innerHTML=x;
}
</script>
</body>
</html>
Next Section
1
2
<!DOCTYPE HTML>
<html>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
submitReset Code
ChapterCourseware