Matlab continue語句

continue語句用於將控件傳遞給for迴圈或while迴圈的下一個迭代。

在MATLAB中的continue語句有點像break語句。 然而,“continue”不是強制終止,而是迫使迴圈的下一次迭代發生,跳過其間的任何代碼。

流程圖

例子

創建腳本檔並鍵入以下代碼 -

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迴圈 下一篇: Matlab向量