Labeled Statement
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

Labeled Statement

Provides an identifier for a statement.

label :
   [statements]

Arguments

label
Required. A unique identifier used when referring to the labeled statement.
statements
Optional. One or more statements associated with label.

Remarks

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

Example

In the following statement the continue statement uses a labeled statement to create an array in which the third column of each row contains and undefined value:

function labelDemo() {
   var a = new Array();
   var i, j, s = "", s1 = "";
   Outer:
   for (i = 0; i < 5; i++) {
      Inner:
      for (j = 0; j < 5; j++) {
         if (j == 2)
            continue Inner;
         else
            a[i,j] = j + 1;
      }
   }
   for (i = 0;i < 5; i++) {
      s = ""
      for (j = 0; j < 5; j++) {
         s += a[i,j];
      }
      s1 += s + "\n";
   }
   return(s1)
}

Requirements

Version 3

See Also

break Statement | continue Statement

Show:
© 2016 Microsoft