目录

continue statement

C#中的continue语句有点像break语句。 但是,不是强制终止,而是继续强制执行循环的下一次迭代,跳过其间的任何代码。

对于for循环, continue语句会导致条件测试并增加循环的部分来执行。 对于whiledo...while循环, continue语句导致程序控制传递给条件测试。

语法 (Syntax)

C#中continue语句的语法如下 -

continue;

流程图 (Flow Diagram)

C#继续声明

例子 (Example)

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
↑回到顶部↑
WIKI教程 @2018