0

I want to use a do while loop in Matlab:

I am currently using this code, but I don't think that I am doing it right:

flag2=true;

while (flag2)

    % (I write the program here)

    for abc = 1:3
        if abs(error(abc)) < errorTreshold
            flag2=false;
            break
        end
    end
end
Wouter J
  • 41,455
  • 15
  • 107
  • 112

1 Answers1

0

You must do:

if abs(error(abc)) > errorTreshold  

instead of "<"

or see if you can do (removing the 'if'):

while abs(error(abc))>errorTreshold
George
  • 5,808
  • 15
  • 83
  • 160
  • is there maybe a method like in java to use do something while condition...as i want the program to at least do something once...and like that i would eliminate the flag – user3074215 Dec 06 '13 at 18:58
  • @user3074215:As far as I know there isn't.The use of flags as you wrote is the appropriate method.If you check it you can see that the first condition is always executed (under 'while').Your error was just the ">" symbol. – George Dec 06 '13 at 19:10