
How can we use Continue and break statement in java program?

The continue statement restart the current loop whereas the break statement causes the control outside the loop. Here is an example of break and continue statement.
Example -
public class ContinueBreak {
public static void main (String args[]){
outer: for(int i=1; i<20; i++){
System.out.println(" ");
if(i>10)break;
for (int j=1; j<20; j++){
System.out.print(" * ");
if(j==i)continue outer ;
}
}
System.out.println("Termination by BREAK");
}
}
Output
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Termination by BREAK
Description: - In the above program, we created a label outer, which contain a block of statement. We are printing right angle triangle of * using for loop. Here we have taken two variable i and j.if i is greater than 10 then break statement will call and control will jump outside the current loop. the continue statement terminate the inner loop when j==i and continue the next iteration of the outer label.