- C# 基礎教程
- C# - 首頁
- C# - 概述
- C# - 環境
- C# - 程式結構
- C# - 基本語法
- C# - 資料型別
- C# - 型別轉換
- C# - 變數
- C# - 常量
- C# - 運算子
- C# - 決策
- C# - 迴圈
- C# - 封裝
- C# - 方法
- C# - 可空型別
- C# - 陣列
- C# - 字串
- C# - 結構體
- C# - 列舉
- C# - 類
- C# - 繼承
- C# - 多型
- C# - 運算子過載
- C# - 介面
- C# - 名稱空間
- C# - 預處理器指令
- C# - 正則表示式
- C# - 異常處理
- C# - 檔案 I/O
C# - continue 語句
C# 中的 continue 語句在某種程度上類似於 break 語句。但是,它並沒有強制終止迴圈,而是強制執行迴圈的下一輪迭代,跳過中間的任何程式碼。
對於 for 迴圈,continue 語句會導致迴圈的條件測試和增量部分執行。對於 while 和 do...while 迴圈,continue 語句會導致程式控制傳遞到條件測試。
語法
C# 中 continue 語句的語法如下:
continue;
流程圖
示例
using System;
namespace Loops {
class Program {
static void Main(string[] args) {
/* local variable definition */
int a = 10;
/* do loop execution */
do {
if (a == 15) {
/* skip the iteration */
a = a + 1;
continue;
}
Console.WriteLine("value of a: {0}", a);
a++;
}
while (a < 20);
Console.ReadLine();
}
}
}
當以上程式碼被編譯並執行時,它會產生以下結果:
value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 16 value of a: 17 value of a: 18 value of a: 19
csharp_loops.htm
廣告