break

The break keyword is used to define a break statement which, without a label, transfers control out of the innermost enclosing while, do, for, or switch statement. If the break statement includes a label and the statement is executed, control will be transferred out of the enclosing statement to the line immediately following the label declaration. (In this case, the break target need not be a while, do, for or switch statement.)

The break statement also transfers control outside of try/catch blocks. Note that if the break statement with a label is executed within a try or catch block, and an associated finally block is defined for the try/catch block, then the contents of the finally block will first be executed. After the entire finally block has executed, control will once again transfer to the first statement immediately following the label declaration.

The following example demonstrates a break statement used with a label:

block1:

   recordsRemain = getUpdateStatus( );

while (recordsRemain)
{
    if (isRunning)
        System.out.println("Update another record");
    else
        break block1;
}