【代码笔记】Web-Javascript-javascript break和continue语句

一,效果图。

【代码笔记】Web-Javascript-javascript break和continue语句

二,代码。

【代码笔记】Web-Javascript-javascript break和continue语句
<!DOCTYPE html>
<html> <head>
<meta charset="utf-8">
<title>javascript break和continue语句</title>
</head> <body>
<!--break语句-->
<p>点击按钮,测试带有brak语句的循环</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>
<!--continue语句-->
<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>
<!--javascript标签-->
<script>
cars = ["BMW", "volvo", "Saab", "Ford"];
list: {
document.write(cars[0] + "<br>");
document.write(cars[1] + "<br>");
document.write(cars[2] + "<br>");
break list;
document.write(cars[3] + "<br>");
document.write(cars[4] + "<br>");
document.write(cars[5] + "<br>");
}
</script>
</body> </html>
【代码笔记】Web-Javascript-javascript break和continue语句

参考资料:《菜鸟教程》

上一篇:oracle追加表空间


下一篇:[BZOJ3796]Mushroom追妹纸:后缀自动机+KMP