Labeled Statement

Provides an identifier for a statement.

语法

label : 
  statements

参数

label

必要参数。A unique identifier used when referring to the labeled statement.

statements

可选参数。One or more statements associated with label.

备注

Labels are used by the break and continue statements to specify the statement to which the break and continue apply.

示例

In the following code, the continue statement refers to the for loop that is preceded by the Inner: statement. When j is 24, the continue statement causes that for loop to go to the next iteration. The numbers 21 through 23 and 25 through 30 print on each line.

Outer: 
for (i = 1; i <= 10; i++) { 
  document.write ("<br />"); 
  document.write ("i: " + i); 
  document.write (" j: "); 
Inner: 
  for (j = 21; j <= 30; j++) { 
   if (j == 24) 
     { 
     continue Inner; 
   } 
   document.write (j + " "); 
 } 
}

必备条件

在以下文档模式中受支持:怪异模式、Internet Explorer 6标准模式、Internet Explorer 7标准模式、Internet Explorer 8标准模式、Internet Explorer 9标准模式、Internet Explorer 10标准模式、Internet Explorer 11标准模式。应用商店应用(Windows 8和Windows Phone 8.1)中也受支持。请参阅版本信息

如果你喜欢这篇文章,敬请给站长打赏↑

除特别注明外,本站所有文章均为本站站长原译,转载请注明出处。