In this tutorial we will discuss about continue statement in java 7.
Continue Statement in java 7
In this tutorial we will discuss about continue statement in java 7.
Continue Statement :
Sometimes you need to skip block of statements under specific condition so for that you can use continue statement in loops.
In java 7, Continue statement stops the current iteration of a for, switch, do-while loop and continue execution with the next iteration. You can categorize continue statement into two parts -
- Unlabeled Continue Statement - It skips the present iteration of the innermost loop
- Labeled Continue Statement
Unlabeled Continue Statement : It skips the present iteration of the innermost loop.
Labeled Continue Statement : This is used where more than one loops are used. It leaves the present iteration of the loop which you can marked with the given label.
Example :
package branching; class ContinueStatement { public static void main(String[] args) { int i; for (i = 1; i <= 10; i++) { if (i % 2 == 0) { System.out.println("Continue statement is called even number..."); continue; } System.out.println("Value of i :" + i); } } }
Output :
Value of i :1 Continue statement is called even number... Value of i :3 Continue statement is called even number... Value of i :5 Continue statement is called even number... Value of i :7 Continue statement is called even number... Value of i :9 Continue statement is called even number...