break和continue
在之前接触到的内容中,break和continue是单独使用,但是事实上,在js中break和continue可以和label标签一起使用,是的break和continue可以跳转到想要的位置
举个例子:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>I am aim at testing the break&continue in script.</p>
<script type="text/javascript">
var count = 0;
breakBlock:
for (var i = 0; i < 10; i++) {
if (count == 2) {
break;
}
count++;
for (var j = 0; j < 10; j++) {
alert(j);
if (j == 5) {
continue breakBlock;
}
}
}
</script>
</body>
</html>
上面这个例子,continue不仅跳出了内部for循环,也跳出了外部for循环。