国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

exit loopbreak

Exit the loop break

The format is as follows:

for(初始條件;判斷條件;循環(huán)后條件值更新)
{  if(特殊情況)
  {break;}
  循環(huán)代碼
}

When a special situation is encountered, the loop will end immediately. Take a look at the example below, which outputs 10 numbers. If the value is 5, it stops outputting.

<html>
<head>
    <script>
        var num;
        for(num=1;num<10;num++){
            if (num==5)
            {
                break;//如果num是5,退出循環(huán)。
            }
            document.write("數(shù)值"+num+"<br />");
        }
    </script>
</head>
<body>
</body>
</html>

The output results are as follows

QQ截圖20161012134415.png

Note: When num=5, the loop will end and the content of the subsequent loop will not be output.

<!DOCTYPE html>
<html>
<body>
<p>點擊按鈕,測試帶有 break 語句的循環(huán)。</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)
    {
    break;
    }
  x=x + "The number is " + i + "<br>";
  }
document.getElementById("demo").innerHTML=x;
}
</script>
</body>
</html>


Continuing Learning
||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>break</title> <script type="text/JavaScript"> var mynum =new Array(70,80,66,90,50,100,89);//定義數(shù)組mynum并賦值 var i=0; while(i<mynum.length) { if(mynum[i]<60) { document.write("成績"+mynum[i]+"不及格,不用循環(huán)了"+"<br>"); break; } document.write("成績:"+mynum[i]+"及格,繼續(xù)循環(huán)"+"<br>"); i=i+1; } </script> </head> <body> </body> </html>
submitReset Code