Replacing a for loop with a while loop?
조회 수: 8 (최근 30일)
이전 댓글 표시
I'm given the following code:
x = 1;
for i = 1:5
x = x*i;
end
And then I'm asked to rewrite the script using a while loop such that it would yeild the same result.
Being relatively new to MATLAB and having a poor grasp on loops, I have no idea how to attempt this.
댓글 수: 0
답변 (2개)
Youssef Khmou
2013년 7월 26일
hi,
Using while, you need to increment the variable manually, :
y=1;
time=1;
while time<6
y=y*time;
time=time+1;
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!