天空是藍色的

          做好軟件為中國 #gcc -c helloworld.c -o helloworld.o //編譯目標文件 #gcc helloworld.o -o helloworld //編譯成可執行exe #helloworld //運行exe
          數據加載中……
          中止for循環break和return有區別么?

          for循環,continue,return,break

                  for(int i=-5;i<1;i++){
                      try{
                          int k 
          = 6/i;
                          System.out.println(k);
                      }catch(Exception e){
                          System.out.println(
          "error");
                          //continue;//忽略錯誤繼續循環
                          return;//中止循環
                          //break;//中止循環
                      }finally{
                          //TODO無論成功失敗都會執行的
                          System.out.println(
          "finally code");
                      }
                  }

          我看用break和return輸出的都一樣

          posted on 2005-12-29 14:55 bluesky 閱讀(13968) 評論(4)  編輯  收藏 所屬分類: 工作總結

          評論

          # re: 中止for循環break和return有區別么? 2006-01-05 09:16 bluesky

          汗~今天才想起來有什么區別了
          break用來中止循環~,且break只能在loop或者switch中,return可以用在loop外邊;
          break中止了循環,循環后的代碼還會執行
          return了后邊的代碼都沒有意義了...
            回復  更多評論    

          # re: 中止for循環break和return有區別么? 2006-07-17 22:36 戰雨災

          ...
          return 的對象是函數
          break 的對象是循環
          ....
            回復  更多評論    

          # re: 中止for循環break和return有區別么? 2006-07-21 16:46 頂“戰雨災”

          @戰雨災
            回復  更多評論    

          # re: 中止for循環break和return有區別么? 2006-07-21 17:05 頂“戰雨災”

          同意“戰雨災”
            回復  更多評論    
          主站蜘蛛池模板: 郧西县| 乌拉特后旗| 博罗县| 柘荣县| 安康市| 如皋市| 亚东县| 漠河县| 咸丰县| 大宁县| 黄山市| 高唐县| 孟津县| 邵阳县| 咸丰县| 鹤峰县| 宜阳县| 庐江县| 无棣县| 卓资县| 灵丘县| 吴旗县| 平江县| 界首市| 白河县| 海伦市| 安西县| 如东县| 长顺县| 育儿| 保康县| 五峰| 西乌珠穆沁旗| 兴隆县| 华容县| 永昌县| 广平县| 海城市| 大洼县| 宝坻区| 孟村|