break 跳出循环体(能够跳出单层循环 也能够跳出多层循环)java
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("学生此次考试成绩是:\n 数学 \t 语文 \t 外语 \t 化学"); 9 NO1: for (int[] is : myscore) { 10 for (int i : is) { 11 System.out.println(i + "\t"); 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 }
输出:spa
1
2
3
4
6
7
8
9code
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 }