How to exit from loop function ?
Show older comments
Hi, I need to exit from a loop,should i use break ?
here is an example :
for j=1:10
if (condition 1)
a=5; % example
% continue step
elseif (condition 2)
a=2;
% continue
elseif (condition 3)
a=0;
% !!! reject step
break; % !!
end
What I do ?
Thanks.
6 Comments
Jan
on 1 May 2021
The question is not clear yet. What does "rejecting a step" mean?
Yamina chbak
on 1 May 2021
Jan
on 1 May 2021
Yes, and you do this already with the break command. So the code does already what you are asking for,
Yamina chbak
on 1 May 2021
Image Analyst
on 1 May 2021
Yamina chbak
on 1 May 2021
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!