Info
この質問は閉じられています。 編集または回答するには再度開いてください。
What does this print out?
1 回表示 (過去 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!