"Return" and "continue" functions!
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (1)
Danupon Subanapong
le 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 commentaires
Jingang Wang
le 4 Déc 2018
I think so.
darova
le 21 Avr 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)
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!