필터 지우기
필터 지우기

Replacing while loop with break command

조회 수: 3 (최근 30일)
Sam
Sam 2013년 6월 11일
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

채택된 답변

David Sanchez
David Sanchez 2013년 6월 11일
clc;clear;close all;
limit=210;
k = 0;
sum = 0;
while sum <= limit
k=k+1;
sum = sum + k;
end
sum
n=k

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by