Documentation
Back to website >

break (JScript)

The"break" statement belongs to the flow control statements and breaks a while or for loop statement. The script is then continued at the first statement, that is, at the start of the loop.

Break is better used in combination with an if condition, so that any number of conditions can be used to terminate a loop.

Syntax

break[label];

Optionally, a label can be specified. This is useful if there are several nested loops. In this case, you can specify the end of the loop to jump to.

Example

var
  x = 12;

while (x > 0)
{
  --x;
  if (x == 5) break;
}

In this example, the while loop is not terminated by the"break" statement if x has the value 0, but already at the value 5.