The Break keyword
Break is used primarily in loop statements or switch statements to jump out of the entire block of statements.
Break jumps out of the innermost loop, and continues execution of the statement below the loop.
Grammar
The use of break is simple, which is a statement in the loop structure:
Break
Instance
public class Test {public static void main (String args[]) {int [] numbers = {10, 20, 30, 40, 50}; for (int x:numbers) {if (x = =) {break; } System.out.print (x); System.out.print ("\ n"); } }}
The results of the above example compilation run as follows:
10 20
Continue keywords
The Continue is suitable for any loop control structure. The function is to let the program jump immediately to the next iteration of the loop.
In the For loop, the continue statement causes the program to jump immediately to the UPDATE statement.
In the while or Do...while loop, the program immediately jumps to the judgment statement of the Boolean expression.
Grammar
Continue is a simple statement in the loop body:
Continue
Instance
public class Test {public static void main (String args[]) {int [] numbers = {10, 20, 30, 40, 50}; for (int x:numbers) {if (x = =) {continue; } System.out.print (x); System.out.print ("\ n"); } }}
The results of the above example compilation run as follows:
10 20 40 50
Java keyword break and continue