I want to return back to a certain loop
Show older comments
I have 3 for loops(not nested for loops) and i want to check on the output coming from the third for loop and if it didn't satisfy a certain condition i want it to loop on the 3 loops again till it reaches an optimum solution! so can anyone help me please?
Accepted Answer
More Answers (1)
Fangjun Jiang
on 10 Mar 2016
Edited: Fangjun Jiang
on 10 Mar 2016
There is no "goto" statement in MATLAB if that is what you are looking for. I think your task could be solved with a recursive function. There is nothing special in MATLAB regarding recursive function. Just search for "recursive function" or "recursive function example" on the web.
function out=MyFun(input)
% do loop 1
% do loop 2
% do loop 3
if out==GOOD
return;
else
out=MyFun(input); % could use modified input if needed
end
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!