MATLAB: Checking if values are equal in a loop

iterationsloops

Hi,
I have a program that estimates some parameters iteratively and returns the value after a set number of iterations of a for loop. Is there a way to get the loop to go on only until the result of two iterations are the same?
Thank you!

Best Answer

Use a while loop:
lastvalue = Inf;
newvalue = -Inf;
while newvalue ~= lastvalue
lastvalue = newvalue;
newvalue = ... %the result of your calculation
end