"Return" and "continue" functions!
Mostra commenti meno recenti
Hello MATLAB experts :)
I have not got the concept of "return" and "continue" functions in MATLAB. I went through the help but the examples were not so comprehensive for me. Please could you kindly explain them with a nice example per each?
Have a nice WE,
Mehdi
Risposta accettata
Più risposte (1)
Danupon Subanapong
il 16 Nov 2018
Very nice explanation, but I have a question. Please see below.
1) Using continue
function VALUE = somefunction
while SOME_CONDITION
DO_THIS;
if SOME_OTHER_CONDITION
continue;
end
DO_THAT
end
VALUE = SOMETHING;
2) No continue just if and ifelse
function VALUE = somefunction
while SOME_CONDITION
DO_THIS;
if ~SOME_OTHER_CONDITION
DO_THAT
else
end
end
VALUE = SOMETHING;
Are these two methods giving the same result?
2 Commenti
Jingang Wang
il 4 Dic 2018
I think so.
darova
il 21 Apr 2020
No
function VALUE = somefunction
while SOME_CONDITION
DO_THIS;
if SOME_OTHER_CONDITION
continue;
end
DO_THAT1
DO_THAT2
DO_THAT3
end
VALUE = SOMETHING;
Ii SOME_OTHER_CONDITION is true then continue skips iteration (all DO_THAT will not be executed)
Categorie
Scopri di più su Programming in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!