Pascal - continue 語句



continue 語句在 Pascal 中的工作方式與 break 語句有些類似。但是,continue 不是強制終止,而只是強制進行迴圈的下一次迭代,跳過中間的任何程式碼。

對於 for-do 迴圈,continue 語句會導致條件測試並執行迴圈的增量部分。對於 while-dorepeat...until 迴圈,continue 語句會使程式控制傳遞給條件測試。

語法

Pascal 中 continue 語句的語法如下 -

continue;

流程圖

Pascal continue statement

示例

program exContinue; 
var
   a: integer;

begin
   a := 10;
   (* repeat until loop execution *)
   repeat
      if( a = 15) then
      
      begin
         (* skip the iteration *)
         a := a + 1;
         continue;
      end;
      
      writeln('value of a: ', a);
      a := a+1;
   until ( a = 20 );
end.

編譯並執行以上程式碼後,將產生以下結果 -

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
pascal_loops.htm
廣告
© . All rights reserved.