天空是藍色的

          做好軟件為中國 #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 閱讀(13962) 評論(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 頂“戰雨災”

          同意“戰雨災”
            回復  更多評論    
          主站蜘蛛池模板: 理塘县| 湖北省| 霍邱县| 泾川县| 大邑县| 铁岭市| 夏津县| 定兴县| 克什克腾旗| 清苑县| 依安县| 桦南县| 德安县| 上高县| 滕州市| 枝江市| 福州市| 巴林左旗| 景谷| 兴隆县| 观塘区| 镇安县| 清原| 龙川县| 德安县| 乌苏市| 天全县| 克东县| 荥阳市| 翁牛特旗| 会泽县| 乌拉特中旗| 商南县| 内丘县| 南昌县| 新化县| 奉节县| 汽车| 余姚市| 洞口县| 新兴县|