For loop comand use
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,I want to compute the sum 2 + 4 + 6 + 8 + 10 + : : : + 100 by using For loop . Can anyone here thankfully help me out?
4 commentaires
James Tursa
le 5 Oct 2017
Modifié(e) : James Tursa
le 5 Oct 2017
Change
total = total + 1;
to
total = total + k; % <-- You need to add the index variable k, not 1 every time
Réponse acceptée
James Tursa
le 5 Oct 2017
The general outline of your for loop would be:
total = 0;
for k=start_value:increment:end_value % <-- you fill in the start_value, increment, and end_value
total = total + something; % <-- you fill in the something
end
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!