结论:break语句会使程序跳出最内侧的循环或退出一个switch语句
例子:
<html>
<head>
<script>
window.onload=function( ){
outerloop:
for(var i=0;i<10;i++){
innerloop:
for(var j=0;j<10;j++){
if(j>3)break;
if(i==2)break innerloop;
if(i==4)break outerloop;
document.write("i="+i+" j="+j+"<br>");
}
//位置1
}
//位置2
document.write("final i="+i+" j="+j+"<br>");
};
</script>
</head>
<body>
</body>
</html>
注:j=3,跳到位置1;i=2,跳到位置1;i=4,跳到位置2。
输出结果:
i=0 j=0
i=0 j=1
i=0 j=2
i=0 j=3
i=1 j=0
i=1 j=1
i=1 j=2
i=1 j=3
i=3 j=0
i=3 j=1
i=3 j=2
i=3 j=3
i=4 j=0 //此值可见js中变量定义域没有块的概念,只要出现在function中,定义域就是该函数。而不是其中的for循环内部。