D語言continue語句


continue語句在D程式設計語言的工作原理有點像break語句。而不是強迫終止,而是繼續強制迴圈發生的下一次疊代,在兩者之間跳過任何程式碼。

對於for迴圈中,continue語句會導致執行迴圈的條件測試和增量部分。對於while和do... while迴圈,continue語句使程式控制通行條件測試。

語法

D語言continue語句語法如下所示:

continue;

流程圖:

D continue statement

例子:

import std.stdio;
 
int main ()
{
   /* local variable definition */
   int a = 10;

   /* do loop execution */
   do
   {
      if( a == 15)
      {
         /* skip the iteration */
         a = a + 1;
         continue;
      }
      writefln("value of a: %d", a);
      a++;
     
   }while( a < 20 );
 
   return 0;
}

當上面的程式碼被編譯並執行,它會產生以下結果:

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