Can anyone replace FOR loop with WHILE loop?

Antworten (1)

Andrei Bobrov
Andrei Bobrov am 9 Dez. 2013
Bearbeitet: Andrei Bobrov am 9 Dez. 2013

0 Stimmen

k = 0;
x = 0;
while x >= 0
k = k + 1;
x = 50 - k^2;
end
y = sqrt(x);

2 Kommentare

x =
-14 ? why?
x have to plus (+)
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 9 Dez. 2013

Kommentiert:

am 9 Dez. 2013

Community Treasure Hunt

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

Start Hunting!

Translated by