Info
此问题已关闭。 请重新打开它进行编辑或回答。
What does this print out?
2 次查看(过去 30 天)
显示 更早的评论
a = 3;
b = a;
a = 1;
while (b<a)
b = b + 1;
disp(b)
end
I thought this would create an infinite loop is that correct?
0 个评论
回答(1 个)
Paulo Silva
2011-5-9
it never prints, the condition is false
do this before the loop
b<a %replacing b and a by their first values you get 3<1
answer is 0 because the condition is false thus the loop never begins
3 个评论
Paulo Silva
2011-5-9
the condition is tested in the while line, if true the while begins, does what's inside it and in the end it tests again the condition, if false the code inside the while loop is "ignored"
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!