MATLAB: I want to return back to a certain loop

loops

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?

Best Answer

Try something like this
again = true
loopCounter = 1
maxIterations = 1000 % Whatever, to prevent infinite loop
while again && loopCounter <= maxIterations
for k1 = 1 : k1Max
% Code

end
for k2 = 1 : k2Max
% Code
end
for k3 = 1 : k3Max
% Code to set some condition
end
if yourCondition == successCriteria
again = false;
end
loopCounter = loopCounter + 1; % Increment loop counter
end