Click to enter _ more _java thousand ask
how break and Contine are used separately
Break,contine are used in the loop body of the statement, there is the role of termination, the specific differences to see the following explanation. The Loop statement looks here:
1. How the Break keyword is used:Break is used to stop the entire loop . Must be in the loop body or in the switch statement (switch syntax here: How switch is used). It will stop the execution of this layer loop (the multilayer loop will only stop the break layer, go out of the parent loop), and begin executing the subsequent code.
Grammar
The break syntax is a separate statement in any loop:
Break
Example:
public class Test {public static void main (String args[]) {int [] numbers = {Ten, A, a,, 50};for (int x:numbers) {if (x = = 30) {break;} SYSTEM.OUT.PRINTLN (x);}}}
this will produce the following results:
10
-
2. How the Continue keyword is used:Continue is used to stop this code in the loop, but the loop continues . It causes the loop to jump immediately to the next iteration, continuing the loop.
In the For loop, continue executes the UPDATE statement immediately. In a while loop or Do/while loop, the flag value is immediately judged. Java looping syntax see here: How to Loop through Java
Grammar
The continue syntax is a separate statement in any loop:
Continue
Example:
public class Test {public static void main (String args[]) {int [] numbers = {Ten, A, a,, 50};for (int x:numbers) {if (x = = 30) {continue;} SYSTEM.OUT.PRINTLN (x);}}}
This will produce the following results:
10
20
40
-
Click to enter Ooppookid's blog
Java technology _java Thousands of questions (0020) _break and contine how to use each