Continue Statement in Java

suggest change

The continue statement skips the rest of the current iteration and starts the next one. In a basic for loop, control goes to the update step (the increment or decrement), if there is one. In an enhanced for, it advances to the next element.

String[] programmers = {"Adrian", "Paul", "John", "Harry"};
// "John" is not printed
for (String name : programmers) {
    if (name.equals("John"))
        continue;
    System.out.println(name);
}

The continue statement can also make the control of the program shift to the step value (if any) of a named loop:

Outer: // The name of the outermost loop is kept here as 'Outer'
for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
        continue Outer;
    }
}

The outer loop needs an update such as i++. With an empty update, continue Outer jumps to a condition that stays true and the loop never ends.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents