Is there a way to call Continue in a loop less script ?

1 次查看(过去 30 天)
Is there any way to call a continue statement in a script that does not contain a loop to continue the caller context loop ?
Since script are just chunks of code that will be runned in the caller context and can access it's variable, it would make sence that the continue statement can affect the caller context's loop.
When a continue is written outside a loop, Matlab's interpreter signals an error. That makes sence because the interpreter has no way to know that this script will be runed in a loop. What dosen't makes sence is that the error is thrown when the script is executed in a suitable context.
Any way to prevent this ?
Thank you all for your time.

采纳的回答

Abdolkarim Mohammadi
编辑:Abdolkarim Mohammadi 2020-11-6
Instead of calling continue directly, you can set a flag in the inner script. The outer script, which contains the loop, uses the flag to continue to the next iteration.
for
% ------------
% inner script
if
flag = 1;
else
flag = 0;
end
% ------------
if flag == 1
continue
end
end
  1 个评论
P Lepage
P Lepage 2020-11-9
编辑:P Lepage 2020-11-9
I will accept this answer since you took the time to reply. The flag strategy was what I was using writing this question. I was looking for a way to use the continue statement since it's self explanatory and simple.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by