Borrar filtros
Borrar filtros

while loop inside a while loop

1 visualización (últimos 30 días)
James Webber
James Webber el 7 de En. de 2022
Respondida: Voss el 7 de En. de 2022
i have one big while loop which loops all of my code and i have a small section within my code which is also in a while loop but i want to know is there a way to stop the middle while loop and go back to the main while loop
while stats
s=input ('would you like to see the game stastics 1,yes 2,no:');
switch s
case 1
num_player = 20;
WLT = zeros(num_player,3);
%disp stastics
if have_a_winner
WLT(winner_index,1) = WLT(winner_index,1) + 1;
WLT(loser_index,2) = WLT(loser_index,2) + 1;
else
WLT(player1_index,3) = WLT(player1_index,3) + 1;
WLT(player2_index,3) = WLT(player2_index,3) + 1;
end
case 2
disp('main menu')
playOn = false;
end
continue
end
this is my middle while loop which i want to cancel if case 2 is choosen and go back to the start of the program

Respuesta aceptada

Voss
Voss el 7 de En. de 2022
while true % main while loop
% some stuff happens
stats = true;
playOn = true;
while stats % little while loop
s=input ('would you like to see the game stastics 1,yes 2,no:');
switch s
case 1
num_player = 20;
WLT = zeros(num_player,3);
%disp stastics
if have_a_winner
WLT(winner_index,1) = WLT(winner_index,1) + 1;
WLT(loser_index,2) = WLT(loser_index,2) + 1;
else
WLT(player1_index,3) = WLT(player1_index,3) + 1;
WLT(player2_index,3) = WLT(player2_index,3) + 1;
end
case 2
disp('main menu')
playOn = false;
break % exit the little while loop
end
end
if ~playOn % start at the top of the main while loop again
continue
end
% other stuff happens
end

Más respuestas (0)

Categorías

Más información sobre Strategy & Logic en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by