Break means to jump directly out of the current loop, and break can only be applied to switch--case statements and loops
Continue means jumping out of the loop and continuing with the next loop
The label tag can choose to break, or continue for which loop statement
For example, to output all numbers from 1 to 10, loop out four rows.
If the i%4==0 break;
If I%4==0 is continue;
1 classtestbreakcontinue2 {3 Public Static voidMain (string[] args)4 {5 /*6 for (int i=1;i<5;i++) {7 for (int j=1;j<=10;j++) {8 if (j%4==0) {9 break;//End Current inner for loop ①Ten //continue;//End the secondary inner for Loop and continue with the next loop ② One } A System.out.print (j); - } - System.out.println (); the } - - */ -Label for(inti=1;i<5;i++) {//Define a tag label + for(intj=1;j<=10;j++){ - if(j%4==0){ + //Break label;//ends the current outer for loop ③ A ContinueLabel//end the second outer for loop, and proceed to the next loop ④ at } - System.out.print (j); - } - System.out.println (); - } - in } -}
Running Result: ④
The difference between break and continue and the use of label labels