<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>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                Rust也有一個`while`循環。它看起來像: ~~~ let mut x = 5; // mut x: u32 let mut done = false; // mut done: bool while !done { x += x - 3; println!("{}", x); if x % 5 == 0 { done = true; } } ~~~ `while`循環是當你不確定應該循環多少次時正確的選擇。 如果你需要一個無限循環,你可能想要這么寫: ~~~ while true { ~~~ 然而,Rust有一個專用的關鍵字`loop`來處理這個情況: ~~~ loop { ~~~ Rust的控制流分析會區別對待這個與`while true`,因為我們知道它會一直循環。現階段理解這些細節_意味著_什么并不是非常重要,基本上,你給編譯器越多的信息,越能確保安全和生成更好的代碼,所以當你打算無限循環的時候應該總是傾向于使用`loop`。 ## 提早結束迭代 讓我們再看一眼之前的`while`循環: ~~~ let mut x = 5; let mut done = false; while !done { x += x - 3; println!("{}", x); if x % 5 == 0 { done = true; } } ~~~ 我們必須使用一個`mut`布爾型變量綁定,`done`,來確定何時我們應該推出循環。Rust有兩個關鍵字幫助我們來修改迭代:`break`和`continue`。 這樣,我們可以用`break`來寫一個更好的循環: ~~~ let mut x = 5; loop { x += x - 3; println!("{}", x); if x % 5 == 0 { break; } } ~~~ 現在我們用`loop`來無限循環,然后用`break`來提前退出循環。 `continue`比較類似,不過不是退出循環,它直接進行下一次迭代。下面的例子只會打印奇數: ~~~ for x in 0u32..10 { if x % 2 == 0 { continue; } println!("{}", x); } ~~~ `break`和`continue`在`while`循環和[`for`循環](http://doc.rust-lang.org/nightly/book/for-loops.html)中都有效。
                  <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>

                              哎呀哎呀视频在线观看