Java Control Statements
- Java if Statement
- Java Nested if Statement
- Java if-else-if Statement
- Java Switch Case
- Java Switch with String
- Java Nested Switch
- Java Simple for Loop
- Java for each Loop
- Java Nested for Loops
- Java while loop
- Java continue Statement with for Loop
- Java continue in do-while Loop
- Java break to Exit a for Loop
- Java break with Nested Loops
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
Control Statements
Java
Java Tutorial
Comments
Post a Comment