Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

What does this print out?

1 Ansicht (letzte 30 Tage)
Cote
Cote am 9 Mai 2011
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
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?

Antworten (1)

Paulo Silva
Paulo Silva am 9 Mai 2011
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 Kommentare
Cote
Cote am 9 Mai 2011
So does it cause an infinite loop since it is a while loop and the condition is never met?
Paulo Silva
Paulo Silva am 9 Mai 2011
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"

Diese Frage ist geschlossen.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by