What is happening in this while loop
조회 수: 2 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
Andreas Justin
2013년 10월 28일
flag = true
while flag
flag=0;
disp('end of loop');
end
see: doc flag
댓글 수: 1
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 Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!