while loop inside a while loop

1 次查看(过去 30 天)
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

采纳的回答

Voss
Voss 2022-1-7
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Strategy & Logic 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by