Azzera filtri
Azzera filtri

Replacing while loop with break command

2 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

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

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by