Can anyone replace FOR loop with WHILE loop?

Respuestas (1)

Andrei Bobrov
Andrei Bobrov el 9 de Dic. de 2013
Editada: Andrei Bobrov el 9 de Dic. de 2013
k = 0;
x = 0;
while x >= 0
k = k + 1;
x = 50 - k^2;
end
y = sqrt(x);

2 comentarios

x =
-14 ? why?
x have to plus (+)
Walter Roberson
Walter Roberson el 9 de Dic. de 2013
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 9 de Dic. de 2013

Comentada:

el 9 de Dic. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by