<html>
<body>
<p>单击该按钮可进行带中断的循环。循环应该输出数字 0 到 4,但是当变量 i 等于“3”时,break 语句退出循环。</p>
<button onclick="myFunction()">试一试</button>
<p id="demo"></p>
<script>
function myFunction() {
var text = "";
var i;
for (i = 0; i < 5; i++) {
if (i === 3) {
break;
}
text += "The number is " + i + "<br>";
}
document.getElementById("demo").innerHTML = text;
}
</script>
</body>
</html>