JavaScript中可以通过continue临时中止循环的某次动作,然后继续执行
<p>Click the button to do a loop which will skip the step where i=3.</p> <button>Try it</button> <p id="demo"></p> 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; }
输出结果,其中循环在i==3时被中止一次,然后继续执行后面的循环
The number is 0 The number is 1 The number is 2 The number is 4 The number is 5 The number is 6 The number is 7 The number is 8 The number is 9