Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Why does this code keep running? player1m=menu(\'Player 1, Choose Rock, Paper, o

ID: 3604891 • Letter: W

Question

Why does this code keep running?

player1m=menu('Player 1, Choose Rock, Paper, or Scissors','Rock', 'Paper','Scissors');
player2m=menu('Player 2, Choose Rock, Paper, or Scissors','Rock', 'Paper','Scissors');

Rock=1;
Paper=2;
Scissors=3;

while player1m == 1
if player2m == 1
result = 'Tie!'
elseif player2m == 2
result = 'Paper Beats Rock so Player 2 wins!'
elseif player2m == 3
result = 'Rock Beats Scissors so Player 1 wins!'
end
end

while player1m == 2
if player2m == 1
result = 'Paper beats Rock So Player 1 wins!'
elseif player2m == 2
result = 'Tie!'
elseif player2m == 3
result = 'Scissors Beats Paper so Player 2 wins!'
end
end

while player1m == 3
if player2m == 1
result = 'Rock Beats scissors so Player 2 wins!'
elseif player2m == 2
result = 'Scissors Beats Paper so Player 1 wins!'
elseif player2m == 3
result = 'Tie!'
end
end

Explanation / Answer

This code will keep running because if the user chooses any of the above valid selection.The reason are as follows:

Hence, this is the reason your program is running continuously and you can improve it with above suggestion.

Thankyou.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote