Difference between a for loop and a while loop (in the context of programming experiments if that adds)

조회 수: 31 (최근 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,

채택된 답변

the cyclist
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개)

카테고리

Help CenterFile Exchange에서 Psychology에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by