[Chapter 5] 5.7 break
Author: David Flanagan
Date: Fri Aug 29 10:52:36 1997

#

| Chapter 5 Statements |

## 5.7 break

The `break` statement has a very simple syntax:

    break;

This statement is valid only within the body of a `while`, `for`, or `for/in` loop. Using it outside of a loop is a syntax error. When executed, the `break` statement exits the currently running loop. This statement is usually used to exit a loop prematurely when, for whatever reason (perhaps when an error condition arises), there is no longer any need to complete the loop. The following example searches the elements of an array for a particular value. If the value is found, a `break` statement terminates the loop:

    for(i = 0; i < a.length; i++) {
        if (a[i] == target)
            break;
    }

for...in |  | continue