本文共 1306 字,大约阅读时间需要 4 分钟。
放段代码,自己反思
private static Listlist = new ArrayList<>(); static { list.add(1); list.add(2); list.add(3); list.add(4); list.add(5); list.add(6); } public static void main(String[] args){ breakTest(); returnTest(); continueTest(); } public static void breakTest(){ System.out.println("breakTest start"); for (Integer i :list){ if (i==4){ break; } System.out.println(i); } System.out.println("breakTest end"); } public static void returnTest(){ System.out.println("returnTest start"); for (Integer i :list){ if (i==4){ return; } System.out.println(i); } System.out.println("returnTest end"); } public static void continueTest(){ System.out.println("continueTest start"); for (Integer i :list){ if (i==4){ continue; } System.out.println(i); } System.out.println("continueTest end"); }
输出结果:
breakTest start
1 2 3 breakTest endreturnTest start
1 2 3continueTest start
1 2 3 5 6 continueTest end转载地址:http://yxgjx.baihongyu.com/