How can I get a infinite loop in matlab?

60 ビュー (過去 30 日間)
Shwetha Rajeev
Shwetha Rajeev 2019 年 3 月 30 日
コメント済み: Walter Roberson 2025 年 3 月 22 日
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!!

回答 (2 件)

Jos (10584)
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 ...')

Ceyhun
Ceyhun 2025 年 3 月 22 日
編集済み: Ceyhun 2025 年 3 月 22 日
ı forgot the put on 'end' in code last ,what can ı do ?
matlab is freezing because of it
  1 件のコメント
Walter Roberson
Walter Roberson 2025 年 3 月 22 日
Type in end at the command console.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by