Filter löschen
Filter löschen

Info

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

I'm confused to how this conversion works for a for to while loop

2 Ansichten (letzte 30 Tage)
Zachary Holmes
Zachary Holmes am 2 Dez. 2015
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
If the for loop is
for i=2:3:20
disp(i);
end
Would the while loop be:
i=2
while (i<20)
i=i+3
disp(i)
end

Antworten (1)

Walter Roberson
Walter Roberson am 2 Dez. 2015
Bearbeitet: Walter Roberson am 2 Dez. 2015
Your question is much improved from what you posted first.
The answer is "not quite". The while loop you have programmed does not display 2.
You need to do the action of the loop before you increment the loop control variable, and you need to be careful about what to do if the control variable is exactly equal to the final allowed value.

Diese Frage ist geschlossen.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by