<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # C++ 中的`do-while`循環 > 原文: [https://beginnersbook.com/2017/08/cpp-do-while-loop/](https://beginnersbook.com/2017/08/cpp-do-while-loop/) 正如上一篇關于[`while`循環](https://beginnersbook.com/2017/08/cpp-while-loop/)的教程中所討論的,循環用于重復一個語句塊,直到給定的循環條件返回`false`。在本教程中,我們將看到`do-while`循環。`do-while`循環類似于`while`循環,但它們之間存在差異:在`while`循環中,首先計算條件,然后執行循環體內的語句,另一方面在`do-while`循環中執行 - 首先執行,然后求值條件。 #### `do-while`循環的語法 ```cpp do { statement(s); } while(condition); ``` ## `do-while`循環如何工作? 首先,循環內的語句執行,然后條件得到求值,如果條件返回`true`,則控制跳轉到`do`以進一步重復執行它,這會重復發生,直到條件返回`false`。一旦條件返回`false`,控制就會跳轉到程序中`do-while`之后的下一個語句。 ![C++ do while loop flow diagram](https://img.kancloud.cn/c5/33/c533f6827cfa61e8d65e460440677b4e_400x400.jpg) ## C++ 中的`do-while`循環示例 ```cpp #include <iostream> using namespace std; int main(){ int num=1; do{ cout<<"Value of num: "<<num<<endl; num++; }while(num<=6); return 0; } ``` **輸出:** ```cpp Value of num: 1 Value of num: 2 Value of num: 3 Value of num: 4 Value of num: 5 Value of num: 6 ``` ## 示例:使用`do-while`循環顯示數組元素 這里我們有一個整數數組,它有四個元素。我們使用`do-while`循環顯示它的元素。 ```cpp #include <iostream> using namespace std; int main(){ int arr[]={21,99,15,109}; /* Array index starts with 0, which * means the first element of array * is at index 0, arr[0] */ int i=0; do{ cout<<arr[i]<<endl; i++; }while(i<4); return 0; } ``` **輸出:** ```cpp 21 99 15 109 ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看