Java continue Statement Inside for Loop Example

This Java example demonstrates how to use a continue Statement inside for loop in Java with an example.

Java continue Statement Inside for Loop Example

package net.javaguides.corejava.controlstatements.loops;

public class ContinueExample {
    public static void main(String args[]) {
        for (int i = 0; i < 10; i++) {
            System.out.print(i + " ");
            if (i % 2 == 0)
                continue;
            System.out.println("");
        }
    }
}
This code uses the % operator to check if i is even. If it is, the loop continues without printing a newline. Here is the output from this program:
0 1
2 3
4 5
6 7
8 9

References


Comments