This documentation is archived and is not being maintained.

break Statement

Terminates the current loop, or if in conjunction with a label, terminates the associated statement.

break [label];


Optional. Specifies the label of the statement you are breaking from.


You typically use the break statement in switch statements and while, for,, or do...while loops. You most commonly use the label argument in switch statements, but it can be used in any statement, whether simple or compound.

Executing the break statement causes the program flow to exit the current loop or statement. Program flow resumes with the next statement immediately following the current loop or statement.

Example 1

The following example illustrates the use of the break statement.

function breakTest(breakpoint){
   var i = 0;
   while (i < 100) {
      if (i == breakpoint)

Example 2

The following example illustrates the use of the labeled break statement.

function nameInDoubleArray(name, doubleArray) {
   var i, j, inArray;
   inArray = false;
   for(i=0; i<doubleArray.length; i++)
      for(j=0; j<doubleArray[i].length; j++)
         if(doubleArray[i][j] == name) {
            inArray = true;
            break mainloop;
   return inArray;


Version 1

See Also

continue Statement | do...while Statement | for Statement | Statement | Labeled Statement | while Statement