What is happening in this while loop

1 回表示 (過去 30 日間)
prasanna
prasanna 2013 年 10 月 28 日
コメント済み: Image Analyst 2013 年 10 月 28 日
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 and if i remove disp statement and figure1 window appears. can anyone explain why?

採用された回答

Andreas Justin
Andreas Justin 2013 年 10 月 28 日
flag = true
while flag
flag=0;
disp('end of loop');
end
see: doc flag
  1 件のコメント
Image Analyst
Image Analyst 2013 年 10 月 28 日
I bet a lot of people don't know flag is the name of a built-in function - I didn't. So it's best to use some other name instead of flag, like keepLooping, or keepGoing, or something. And your point of initializing flag prior to entering the loop is really the key issue here (because you could actually overwrite the flag function with your own variable of the same name if you wanted to, though it's not advised).

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by