How to use while true loop

26 ビュー (過去 30 日間)
mahmoud Tarek
mahmoud Tarek 2020 年 9 月 19 日
コメント済み: Walter Roberson 2020 年 9 月 19 日
i want solved exambls..

回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 9 月 19 日
while true
x = rand();
if x < 0.1; break; end
end
  1 件のコメント
Walter Roberson
Walter Roberson 2020 年 9 月 19 日
As I posted recently when someone asked about "do while", the pattern in MATLAB is:
do while
some statements
if ~condition; break; end
end
Another example:
while true
a = randi(20); b = randi(20); c = randi(20);
if a^2+b^2 == c^2; break; end
end
This finds a random pythagorean triple.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by