Difference between a for loop and a while loop (in the context of programming experiments if that adds)
7 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
What is the key differences between a for loop and a while loop? I am having trouble understanding such a difference.
Thanks for your time,
0 个评论
采纳的回答
the cyclist
2021-5-5
As a general rule, use a for loop when you know exactly how many iterations you need:
for m = 1:10
...
end
Use a while loop when you don't know how many iterations, but instead base it on a condition:
while mm < mm_max
... % This line might change the values of mm or mm_max, so you don't know how many iterations
end
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!