continue

The continue keyword is used in nested loops to define a continue statement, which, without a label, transfers control to the end of the innermost enclosing while, do, or for loop. Once control is passed, the current loop iteration ends and a new one begins. If the continue statement includes a label and is executed, control is transferred to the last statement of the outer loop. In this case, the continue target label must point to a while, do, or for loop. (Contrast this with the labeled break statement, where the target need not be a loop, or iteration, statement.)

Note that if the continue 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 be executed first. After the entire finally block has executed, control will once again transfer to the last statement of the loop immediately following the label declaration.

The following code demonstrates the continue keyword used with and without a label:

block1:
for ( int i = 0; i < 10; i++ )
{
    while ( statusOkay )
    {
        if ( someNum < 0 )
        {
            someNum++;
            System.out.println("Do it again");
            continue;
        }
        
        if (string1[i] == null)
        {
            System.out.println("null string here");
            continue block1;
        }
        else
        {
            string2[i] = string1[i];
        }
    // continue statement without label points here
    }
// continue statement with label points here
}