Continue Statement in Java
The Continue Statement in Java is used to continue loop. It is widely used inside loops. Whenever the continue statement is encountered inside a loop, control immediately jumps to the beginning of the loop for next iteration by skipping the execution of statements inside the body of loop for the current iteration.
Syntax:
continue;
Sample Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
package ClassThreeControlFlowStatements; Â public class ContinueStatement { Â public static void main(String[] args) { Â for (int i=1; i<=10; i++) { /* I have mentioned continue statement inside if condition where i is equal to 4 * if i value is equal to 4 then the control goes to continue statement and * the control jumps at the begining of for loop for next iteration without executing * print statement. * So, the output "Value of i is 4" wont display in the console. */ if (i==4) Â Â Â Â Â Â Â Â { continue; Â Â Â Â Â Â Â Â } Â Â Â Â Â Â Â Â System.out.println("Value of i is "+i); } } Â } |
Must Read: Java Tutorial