Break,Continue,Return

break  跳出循环体(可以跳出单层循环 也可以跳出多层循环)

1 lable:
2 for(元素变量 x:遍历对象 obj){
3       for(元素变量 x1:遍历对象 obj1){
4             if(条件表达式){
5             break lable;
6        }
7    }  
8 }

continue  停止执行continue后面代码 结束本次循环 进行下一次循环(又叫循环体的过滤器)

 1 package com.JunitTest.www;
 2 
 3 import java.util.Iterator;
 4 
 5 public class BreaakDemo {
 6     public static void main(String[] args) {
 7         int[][] myscore = new int[][] { { 72, 78, 63, 22, 66 }, { 13, 75, 66, 262, 66 }, { 62, 68, 66, 62, 66 } };
 8         System.out.println("学生这次考试成绩是:
 数学 	 语文 	 外语 	 化学");
 9         NO1: for (int[] is : myscore) {
10             for (int i : is) {
11                 System.out.println(i + "	");
12                 if (i < 60) {
13                     System.out.println("");
14                     break NO1;
15                 }
16             }
17         }
18     }
19 }

 

1 public static void testContinue(){
2         int[] xx = {1,2,3,4,5,6,7,8,9};
3         for (int i = 0; i < xx.length; i++) {
4             if (xx[i]==5) {
5                 continue;
6             }
7             System.out.println(xx[i]);
8         }
9     }

输出:

1
2
3
4
6
7
8
9

return 返回函数

 1     public static int getReturns() {
 2         int[] xx = { 1, 2, 3, 4, 5, 6 };
 3         int a = 0;
 4         for (int x : xx) {
 5             if (x == 3) {
 6                 a = x;
 7             }
 8         }
 9         return a;
10     }
原文地址:https://www.cnblogs.com/QQ931697811/p/4953256.html