Can anyone replace FOR loop with WHILE loop?
이전 댓글 표시
for k=1:10
x=50-k^2;
if x<0
break
end
y=sqrt(x)
end
답변 (1개)
Andrei Bobrov
2013년 12월 9일
편집: Andrei Bobrov
2013년 12월 9일
k = 0;
x = 0;
while x >= 0
k = k + 1;
x = 50 - k^2;
end
y = sqrt(x);
댓글 수: 2
misha Bilguun
2013년 12월 9일
Walter Roberson
2013년 12월 9일
Not in your code. Your "for" loop tests x<0 after it sets x to the new value. So the loop is not going to end until it is already true that x<0.
카테고리
도움말 센터 및 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!