看到网上的这道面试题都只是提供了break,不是很全面
说一下其他的两种:
1.return
public static String testOutFor() throws Exception { for(int i = 0 ; i < 10; i++) { System.out.println("i:"+i); for(int j=0;j<5;j++) { System.out.println("j:"+j); if(i==6) { return "end"; } } } return null; }
2.throw exception
public static String testOutFor() throws Exception { for(int i = 0 ; i < 10; i++) { System.out.println("i:"+i); for(int j=0;j<5;j++) { System.out.println("j:"+j); if(i==6) { throw new Exception("end"); } } } return null; }
原文:http://blog.csdn.net/test_ld/article/details/19407819