continue
The continue keyword is used to skip one particular iteration if the specific condition is true.
Example:
package quipohouse;
public class ContinueStatement {
public static void main(String[] args) {
int i;
for (i = 0; i < 5; i++) {
if (i == 2) {
continue;
}
System.out.println(i);
}
}
}
Output:
0
1
3
4
Key Point
- Skips execution of the current iteration and moves to the next iteration.
- Used inside loops (for, while, do-while).
- Does not terminate the loop, unlike break.
1. The loop runs from i = 0 to i < 5.
2. When i == 2, the continue statement is triggered.
3. The loop skips printing 2 and continues with the next iteration.
2. When i == 2, the continue statement is triggered.
3. The loop skips printing 2 and continues with the next iteration.