Can anyone replace FOR loop with WHILE loop?
显示 更早的评论
回答(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!