label statementS2C Home « Statements « label statement

An identifer and statement that passes control to the code after the identifier.

Description

The label statement allows us to code a label identifier that we can pass control flow to from a break or continue statement.

Syntax

Signature Description
label:
   statement
Allows us to code a label identifier that we can pass control flow to from a break or continue statement.

Parameters

Parameter Description
labelAny non reserved word identifier.
statementThe labelled position from where to pass control.

Examples

The code below shows an example of the label statement used with continue.


// execute the loop until loop condition is false.
for (var i=1; i<3; i++) {
  atLabel:
  for (var k=1; k<3; k++) {
    if (k == 2) {
      continue atLabel; 
    }
    alert('The i variable is = ' + i + ' and k variable is = ' + k);
  }
}
alert('left for loop');


Press the button below to action the above code:


Related Tutorials

JavaScript Intermediate Tutorials - Lesson 4 - While and Do....While Loops
JavaScript Intermediate Tutorials - Lesson 5 - For Loops

go to home page Homepage go to top of page Top