MATLAB: How to go back in previous iteration

how to go back in previous itreartion

i was trying to run an iterative process in while loop.it is conditional based iteration, if the condition is satisfied in current iteration then continue to next iteration else go to previous iteration as long as condition is not satisfied.
i have considered iter=iter-1 for previous itertion in if loop and then used break command to terminate while loop . will it go back in previous iteration with this condition. suggestion will be appreciated.
thanks in advance…

Best Answer

The only way to go back to a previous iteration is to use a while loop and make the loop counter the appropriate previous value and then "continue".
It is much more common to want to stay on the current iteration until a condition is satisfied. For that, you can use a while loop within a for loop
for K = 1 : number_of_iterations
while true
do a calculation
if condition is satisfied
break
end %end if
end %end while
end %end for
Related Question