Java continue Statement in while Loop Example

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

Using continue Statement in while Loop Example

package net.javaguides.corejava.controlstatements.loops;

public class ContinueExample {
    public static void main(String args[]) {
        int count = 10;
        while (count >= 0) {
            if (count == 7) {
                count--;
                continue;
            }
            System.out.println(count + " ");
            count--;
        }
    }
}
Output:
10 
9 
8 
6 
5 
4 
3 
2 
1 
0 
Note that we are iterating this loop from 10 to 0 for counter value and when the counter value is 7 the loop skipped the print statement and started the next iteration of the while loop.

Reference



Comments