Clear Filters
Clear Filters

using return command before codes

1 view (last 30 days)
sermet on 6 Jun 2015
Answered: the cyclist on 6 Jun 2015
while (criterion for loop)
%codes to perform
if iteration==200
errordlg('iteration cannot be converged', 'Error!', 'modal')
%other codes need to be performed independently after the above loop
%In this example, if iteration numbers reach 200, return command terminates the loop to eliminate infinite loop. But there are other codes right after the loop which need to be executed. How can I continue to execute other codes outside the loop with using return command.

Accepted Answer

the cyclist
the cyclist on 6 Jun 2015
It sounds like you want the break command rather than return command. A similar one is the continue command, but I don't think that's what you want in this case.

More Answers (0)


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!