필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

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

조회 수: 2 (최근 30일)
Zachary Holmes
Zachary Holmes 2015년 12월 2일
마감: MATLAB Answer Bot 2021년 8월 20일
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

답변 (1개)

Walter Roberson
Walter Roberson 2015년 12월 2일
편집: Walter Roberson 2015년 12월 2일
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.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by