필터 지우기
필터 지우기

What is the possible code that can be used to return to primary while?

조회 수: 1 (최근 30일)
arwa
arwa 2016년 12월 23일
댓글: Image Analyst 2016년 12월 23일
hi, I have this code ;
while(true) % primary while(step 1)
while(true)
if (condition)
statement
...
statement
continue
end
end
while(true)
if (condition)
statement
...
statement
(??) % Here, I want to return to primary while (i.e step 1)
else
end
end
What is the possible code that can be used at (??) mark?

답변 (1개)

Les Beckham
Les Beckham 2016년 12월 23일
Use 'break'
  댓글 수: 2
Image Analyst
Image Analyst 2016년 12월 23일
but that won't fix your second while. That loop will never exist because you don't have a break in it, so you'll never even get to the third while. A "continue" merely tosses control to the bottom of the while loop but let's it continue, forever in your case. You should always have a failsafe in your loop conditions to prevent infinite loops.

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

카테고리

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