【目录】 【上一页】 【下一页】 【索引】
break
Terminates the current while or for loop and transfers program control to the statement following the terminated loop.
语法
break break label
Argument
描述
The break statement can now include an optional label that allows the program to break out of a labeled statement. This type of break must be in a statement identified by the label used by break.
The statements in a labeled statement can be of any type.
示例
The following function has a break statement that terminates the while loop when e is 3, and then returns the value 3 * x.
function testBreak(x) { var i = 0 while (i < 6) { if (i == 3) break i++ } return i*x }
In the following example, a statement labeled checkiandj contains a statement labeled checkj. If break is encountered, the program breaks out of the checkj statement and continues with the remainder of the checkiandj statement. If break had a label of checkiandj, the program would break out of the checkiandj statement and continue at the statement following checkiandj.
checkiandj : if (4==i) { document.write("You've entered " + i + ".<BR>"); checkj : if (2==j) { document.write("You've entered " + j + ".<BR>"); break checkj; document.write("The sum is " + (i+j) + ".<BR>"); } document.write(i + "-" + j + "=" + (i-j) + ".<BR>"); }
参看
labeled, switch
【目录】 【上一页】 【下一页】 【索引】
|