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

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # break(C# 參考) **break** 語句用于終止最近的封閉循環或它所在的 [switch](https://msdn.microsoft.com/zh-CN/library/06tc147t.aspx) 語句。控制傳遞給終止語句后面的語句(如果有的話)。 在此示例中,條件語句包含一個應從 1 計數到 100 的計數器;但 **break** 語句在計數器計數到 4 后終止了循環。 ``` class BreakTest { static void Main() { for (int i = 1; i <= 100; i++) { if (i == 5) { break; } Console.WriteLine(i); } // Keep the console open in debug mode. Console.WriteLine("Press any key to exit."); Console.ReadKey(); } } /* Output: 1 2 3 4 */ ``` 在此示例中,**break** 語句用于中斷內層嵌套循環,并將控制權返回給外層循環。 ``` class BreakInNestedLoops { static void Main(string[] args) { int[] numbers = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; char[] letters = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' }; // Outer loop for (int x = 0; x < numbers.Length; x++) { Console.WriteLine("num = {0}", numbers[x]); // Inner loop for (int y = 0; y < letters.Length; y++) { if (y == x) { // Return control to outer loop break; } Console.Write(" {0} ", letters[y]); } Console.WriteLine(); } // Keep the console open in debug mode. Console.WriteLine("Press any key to exit."); Console.ReadKey(); } } /* * Output: num = 0 num = 1 a num = 2 a b num = 3 a b c num = 4 a b c d num = 5 a b c d e num = 6 a b c d e f num = 7 a b c d e f g num = 8 a b c d e f g h num = 9 a b c d e f g h i */ ``` 下面的示例演示 **break** 在 [switch](https://msdn.microsoft.com/zh-CN/library/06tc147t.aspx) 語句中的用法。 ``` class Switch { static void Main() { Console.Write("Enter your selection (1, 2, or 3): "); string s = Console.ReadLine(); int n = Int32.Parse(s); switch (n) { case 1: Console.WriteLine("Current value is {0}", 1); break; case 2: Console.WriteLine("Current value is {0}", 2); break; case 3: Console.WriteLine("Current value is {0}", 3); break; default: Console.WriteLine("Sorry, invalid selection."); break; } // Keep the console open in debug mode. Console.WriteLine("Press any key to exit."); Console.ReadKey(); } } /* Sample Input: 1 Sample Output: Enter your selection (1, 2, or 3): 1 Current value is 1 */ ``` 如果輸入了 4,則輸出為: ``` Enter your selection (1, 2, or 3): 4 Sorry, invalid selection. ``` ## C# 語言規范 有關詳細信息,請參閱 [C# 語言規范](https://msdn.microsoft.com/zh-CN/library/ms228593.aspx)。該語言規范是 C# 語法和用法的權威資料。 ## 請參閱 [C# 參考](https://msdn.microsoft.com/zh-CN/library/618ayhy6.aspx) [C# 編程指南](https://msdn.microsoft.com/zh-CN/library/67ef8sbd.aspx) [C# 關鍵字](https://msdn.microsoft.com/zh-CN/library/x53a06bb.aspx) [switch(C# 參考)](https://msdn.microsoft.com/zh-CN/library/06tc147t.aspx) [跳轉語句(C# 參考)](https://msdn.microsoft.com/zh-CN/library/d96yfwee.aspx) [迭代語句(C# 參考)](https://msdn.microsoft.com/zh-CN/library/32dbftby.aspx)
                  <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>

                              哎呀哎呀视频在线观看