how to set the maximum iteration while looping

조회 수: 12 (최근 30일)
SITI AISHAH
SITI AISHAH 2019년 10월 6일
댓글: SITI AISHAH 2019년 10월 6일
m=50;
c=10;
tol=m-c;
while tol>0
c=c+5;
tol=m-c;
if tol<0;
break
else
disp 'amacam?'
end
disp ('Table for iteration');disp (' m c tol ');
format shortG
disp ([m',c',tol',]);
end
**I want to stop the looping at 5th iteration wihout considering the value of tol. Can somebody help?

채택된 답변

Walter Roberson
Walter Roberson 2019년 10월 6일
Before the loop:
iter = 0;
Then change the while to
while iter <= 5 && tol > 0
iter = iter + 1;
  댓글 수: 3
Walter Roberson
Walter Roberson 2019년 10월 6일
You should think through whether you want to test iter <= 5 or iter < 5
SITI AISHAH
SITI AISHAH 2019년 10월 6일
Alright

댓글을 달려면 로그인하십시오.

추가 답변 (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