# Problem with while-end loop [closed]

This is a peice of code written in Matlab:

while flag==1
flag = 0;
disp('end of loop');
end


Surprisingly, this does not display the string. If I remove the disp statement a figure1 window appears. Can anyone explain why?

• Since this question is more about programming than computational science, I would suggest moving it to stack overflow. – Dr_Sam Oct 28 '13 at 12:33

That is simply because flag is a defined command in matlab. Try typing flag just after having started Matlab and you will see a non-empty matrix appearing. If you type help flag you will see the meaning of that function.
Also, the function is selected by Matlab because you do not declare a variable called flag before your code. If you write flag=1 before your code, it works as expected.
myflag = 1;