MATLAB - continue 語句



continue 語句用於將控制權傳遞到 for 或 while 迴圈的下一迭代。

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

流程圖

MATLAB continue statement

示例

建立一個指令碼檔案並輸入以下程式碼:

a = 9;
%while loop execution 
while a < 20
   a = a + 1; 
   if a == 15
      % skip the iteration 
      continue;
   end 
fprintf('value of a: %d\n', a);
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
value of a: 20
matlab_loops.htm
廣告
© . All rights reserved.