How to use while true loop
209 次查看(过去 30 天)
显示 更早的评论
回答(1 个)
Walter Roberson
2020-9-19
while true
x = rand();
if x < 0.1; break; end
end
1 个评论
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 Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!