34 break与return的区别

break 用于跳出循环

return 用于停止方法

 

 1 public class Add9 {
 2     public static void main(String[] args) {
 3 
 4         for (int i = 1; i <=9 ; i++) {
 5             if(i%3==0){
 6                 return;  // 跳出循环;
 7 
 8             }
 9 
10         }
11 
12         System.out.println("aaa");
13     }
14 }

 

posted @ 2017-01-22 15:40  panw3i  阅读(101)  评论(0编辑  收藏  举报