Creating an infinite loop until an event occurs?

조회 수: 19 (최근 30일)
Mark
Mark 2012년 6월 26일
편집: Walter Roberson 2019년 7월 26일
I am trying to make a loop until a certain event happens. In my first drafts I simply let it run for a large number of steps. However, now that I am adding a few extra steps in between, and want it to stop, it is no longer viable. Before I could run
N=100 for t=1:N (calculations) End
Which would do the loop 100 times. However, now I want it to continue forever until a certain event occurs. So now I am getting to:
N=10000 for t=1:N (calculations)
if (calculations) End % and finish here completely and do not engage in any more loops
Else (more calculations) End % and this should repeat back to the ‘for’ statement
Is there any way I can have this loop continuing, and block it in the middle after a certain event? Otherwise, is there another way of doing it?

채택된 답변

Stephen
Stephen 2012년 6월 26일
go = true;
while go
step1
step2
step3
if step3==stopcriteria
go=false
end
end
  댓글 수: 2
Walter Roberson
Walter Roberson 2012년 6월 26일
편집: Walter Roberson 2019년 7월 26일
Or
while true
step1
step2
step3
if step3==stopcriteria; break; end
end
Mark
Mark 2012년 6월 26일
Sorry it took a while to answer. I was playing with the code but it finally worked, and I thank you very much for your precise answers!

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

추가 답변 (1개)

Erencem Özbey
Erencem Özbey 2018년 7월 12일
what is step1 step2 step 3
  댓글 수: 1
N/A
N/A 2019년 7월 25일
That just represents various lines of code. like what you want to do while in the "while true" loop

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

카테고리

Help CenterFile Exchange에서 Get Started with MuPAD에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by