6月 292016
当continue遇上finally,continue执行后仍会执行finally中的代码,如下代码:
1 2 3 4 5 6 7 8 9 10 11 12 |
public static void main(String[] args){ for(int i = 1; i < 11; i++){ try{ if(i % 5 == 0){ System.out.println("continue: i = " + i); continue; } } finally { System.out.println("finally: i = " + i); } } } |
运行输出结果:
1 2 3 4 5 6 7 8 9 10 11 12 |
finally: i = 1 finally: i = 2 finally: i = 3 finally: i = 4 continue: i = 5 finally: i = 5 finally: i = 6 finally: i = 7 finally: i = 8 finally: i = 9 continue: i = 10 finally: i = 10 |
Sorry, the comment form is closed at this time.