stop for loop if a thing happens

6 views (last 30 days)
mohammad
mohammad on 8 Sep 2011
Commented: feras almasri on 4 Apr 2015
for example:
for i=1:10
a=i+1
if a>5
exit from loop % *which command do this*
end
end

Accepted Answer

Jan
Jan on 8 Sep 2011
Or BREAK.
You can find a list of commands concerning FOR loops in the "See also" line of help for. This line is created exactly for such questions.

More Answers (2)

Wesley Ooms
Wesley Ooms on 8 Sep 2011
the command is 'return' i guess

Wesley Ooms
Wesley Ooms on 8 Sep 2011
i looked it up for you. the command is 'break' :)
  2 Comments
Oleg Komarov
Oleg Komarov on 8 Sep 2011
@Weasley: please edit your answers in place of creating new ones.
feras almasri
feras almasri on 4 Apr 2015
plz answer him instead of saying this

Sign in to comment.

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!