how to remain in the loop until the user gives the specific command?

8 visualizaciones (últimos 30 días)
I want to run a loop with having some instruction after those instruction it should ask weather to remain in the loop or exit the loop. how can i implement this ?

Respuesta aceptada

Walter Roberson
Walter Roberson el 17 de Oct. de 2016
Editada: Walter Roberson el 17 de Oct. de 2016
while true
fprintf('Watch the chicken cross the road!\n');
YN = input('Do you know why yet? Y or N', 's');
if strcmpi(YN, 'y')
break;
end
for K = 1 : randi(3)
fprintf('Cluck! ');
end
fprintf('\n');
end
fprintf('Bawk!\n');

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by