while loop inside a while loop

2 visualizzazioni (ultimi 30 giorni)
James Webber
James Webber il 7 Gen 2022
Risposto: Voss il 7 Gen 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

Risposta accettata

Voss
Voss il 7 Gen 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

Più risposte (0)

Categorie

Scopri di più su Strategy & Logic in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by