How to use while true loop

Respuestas (1)

Walter Roberson
Walter Roberson el 19 de Sept. de 2020

0 votos

while true
x = rand();
if x < 0.1; break; end
end

1 comentario

Walter Roberson
Walter Roberson el 19 de Sept. de 2020
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

el 19 de Sept. de 2020

Comentada:

el 19 de Sept. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by