Effacer les filtres
Effacer les filtres

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

9 vues (au cours des 30 derniers jours)
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,

Réponse acceptée

the cyclist
the cyclist le 5 Mai 2021
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

Plus de réponses (0)

Catégories

En savoir plus sur Psychology dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by