While Loops - TextBook Example
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Maroulator
il 9 Ago 2014
Risposto: Matthew Eicholtz
il 9 Ago 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?
0 Commenti
Risposta accettata
Più risposte (2)
Azzi Abdelmalek
il 9 Ago 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
0 Commenti
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!