break

The break statement exits from the current for, for..in, for..of, switch, or while statement and transfers execution to the statement following the terminated statement.

Syntax


    break;

Example: break out of a loop

The following example is similar across for, for..in, for..of, and while statements and breaks out of a loop.

<?ev
    for(var i=0; i<5; i++){
        if(i==3){
            break;
        }
        print(i);
    }
?>

Example: break out of a switch

The following example illustrates breaking out of a switch statement from a case clause.

<?ev
    switch(val){
        case 1: 
            print('One');
            break;
        case 2:
            print('Two');
            break;
        default:
            print('Many');
    }
?>

See also continue