Replacing a for loop with a while loop?
4 ビュー (過去 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!