Borrar filtros
Borrar filtros

While Loops - TextBook Example

3 visualizaciones (últimos 30 días)
Maroulator
Maroulator el 9 de Ag. de 2014
Respondida: Matthew Eicholtz el 9 de Ag. de 2014
I have the following code from my textbook:
ires=2;
while ires<=200
ires=ires^2;
end
I estimate that the above code will run 14 times and give me a final value of 225 for variable ires. When I run the code in MatLab, however, I get 15 runs and a final value of 256 for variable ires. Could anyone provide some insight as to why this may be the case?

Respuesta aceptada

Image Analyst
Image Analyst el 9 de Ag. de 2014

Más respuestas (2)

Azzi Abdelmalek
Azzi Abdelmalek el 9 de Ag. de 2014
You can check how many times your while loop runs
ires=2;
k=0;
while ires<=200
k=k+1
ires=ires^2;
end
In your case k=3 and not 14

Matthew Eicholtz
Matthew Eicholtz el 9 de Ag. de 2014
2^2=4
4^2=16
16^2=256
256>200

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by