Replacing while loop with break command

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

 Respuesta aceptada

David Sanchez
David Sanchez el 11 de Jun. de 2013
clc;clear;close all;
limit=210;
k = 0;
sum = 0;
while sum <= limit
k=k+1;
sum = sum + k;
end
sum
n=k

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

Sam
el 11 de Jun. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by