How can I get a infinite loop in matlab?
조회 수: 53 (최근 30일)
이전 댓글 표시
I'm writing a code and I need to loop the a section of the code infinite number of times. Does MATLAB any code that is equivalent to label goto, that I can use? Thanks in advance!!
댓글 수: 0
답변 (2개)
Jos (10584)
2019년 3월 30일
an infinite loop
k = 0 ;
while true
% useful code here
k = k + 1 ;
disp(k)
end
But are you sure you want an infinite loop? This will mean you cannot do anything with matlab till the end of times ...
Maybe, you are also interested in the function break
k = 0 ;
while true
k = k + 1 ;
if k > randi(999,1)
break
end
disp(k)
end
disp('End of Times reached ...')
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!