【代码笔记】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>
参考资料:《菜鸟教程》
本文来自博客园,作者:花儿迎风笑,转载请注明原文链接:https://www.cnblogs.com/yang-guang-girl/p/10166866.html