repeating the loop until condition is met

조회 수: 6 (최근 30일)
NETHRAVATHI S
NETHRAVATHI S 2021년 4월 23일
댓글: DGM 2021년 4월 24일
Hello,
I have a prog, in which I have to repeat the function until a condition is met.
I used while loop, but it is running only once and coming out of the loop.
My code looks somewhat like this. It is a lengthy prog, hence just posting the gist.
iteration=0
while 1
calling a function which will give me an array
the returned array is checked to meet a specific requirement
if the requirement is not met, then call the function again.
iteration=iteration+1;
end
  댓글 수: 4
per isakson
per isakson 2021년 4월 24일
편집: per isakson 2021년 4월 24일
More standard
thinghappens = false;
while not( thinghappens )
% do stuff
end
DGM
DGM 2021년 4월 24일
I can agree to that, but I was hoping that the obvious hint would be that the two can be combined.
while ~normalexitcondition
% do stuff
if abnormalexitcondition
warning('oh no!')
break;
end
end

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

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