how to set the maximum iteration while looping

18 次查看(过去 30 天)
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;

更多回答(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