The continue Statement

The continue Statement

class Demo {
    public static void main(String[] args) {

        String searchMe = "peter piper picked a " + "peck of pickled peppers";
        int max = searchMe.length();
        int numPs = 0;

        for (int i = 0; i < max; i++) {
            // interested only in p's
            if (searchMe.charAt(i) != 'p')
                continue;

            // process p's
            numPs++;
        }
        System.out.println("Found " + numPs + " p's in the string.");
    }
}
  • Skips the current iteration of a for, while , or do-while loop.
  • The unlabeled form skips to the end of the innermost loop's body and evaluates the boolean expression that controls the loop.
  • A labeled continue statement skips the current iteration of an outer loop marked with the given label.

Related concepts

The continue Statement

The continue Statement — Structure map

Clickable & Draggable!

The continue Statement — Related pages: