Effacer les filtres
Effacer les filtres

Replacing while loop with break command

2 vues (au cours des 30 derniers jours)
Sam
Sam le 11 Juin 2013
Need help rewriting the following MATLAB code using a while loop, to avoid using the break command.
clc;clear;close all;
limit=210;
m=100;
sum=0;
for i=1:m
sum=sum+i;
if sum>limit
break
end
end
sum
n=i

Réponse acceptée

David Sanchez
David Sanchez le 11 Juin 2013
clc;clear;close all;
limit=210;
k = 0;
sum = 0;
while sum <= limit
k=k+1;
sum = sum + k;
end
sum
n=k

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by