Continue vs Break

Continue means jump out this time, You could use it to find out all the odd numbers. When you find even numbers, you just jump out the code block this time and continue to run the code block.

public class Main {
    public static void main(String[] args) {
        for (int i=1; i<11; i++) {
            if(i % 2 == 0) {
                continue;
            }
            System.out.println(i);
        }

    }
}

The snippet result is

1 3 5 7 9

Break means jump out this block. You could use it to jump out the cold block when you find the first even number.

public class Main {
    public static void main(String[] args) {
        for (int i=1; i<11; i++) {
            if(i % 2 == 0) {
                break;
            }
            System.out.println(i);
        }

    }
}

The snippet result is

1

Last updated