How to use while true loop

조회 수: 44 (최근 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 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