Biblioteca Java - Rev 4

Subversion Repositories:
Rev:
package inroducere.java.breackcontinue;

/**
 * Exemplify the use of the continue statement. This can be used to skip the current
 * iteration of a for, while , or do-while loop.
 */

class ContinueDemo {
    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.");
    }
}