how to set the maximum iteration while looping

7 Ansichten (letzte 30 Tage)
SITI AISHAH
SITI AISHAH am 6 Okt. 2019
Kommentiert: SITI AISHAH am 6 Okt. 2019
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?

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 6 Okt. 2019
Before the loop:
iter = 0;
Then change the while to
while iter <= 5 && tol > 0
iter = iter + 1;
  3 Kommentare
Walter Roberson
Walter Roberson am 6 Okt. 2019
You should think through whether you want to test iter <= 5 or iter < 5
SITI AISHAH
SITI AISHAH am 6 Okt. 2019
Alright

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by