How to stop while loop with 2 conditions | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to stop while loop with 2 conditions

Hello everyone! I would like to know how can I stop a while loop when one of my condition get True, instead using the break coomand. Here is my code and I would like to stop my while loop when player 1 or player 2 get 3 victories first. (As I'm quite new here, I'm not looking for a fancy solution, since Ive just study till the while loop topic :p) Thank you! --------------------------------------- #ROCK-PAPER-SCISSORS #learning the while loop import random num1 = random.randint (1,3) #1 - Rock, 2 - Paper, 3 - Scissors num2 = random.randint (1,3) w1 = 0 # Victories Counter for Player 1 w2 = 0 # Victories Counter for Player 2 print('Welcome to Rock-Paper-Scissors Game') while w1 < 3 or w2 < 3: if num1 == 1 and num2 == 1: print ('\nPlayer 1 - Rock') print ('Player 2 - Rock') print ('It is a Draw') #nobody receive a victory w1 += 0 w2 += 0 if w1 == 3: break elif w2 ==3: break else:

2nd Jul 2018, 11:54 PM
Konstantinos Polemis JĂșnior
Konstantinos Polemis JĂșnior - avatar
5 Answers
+ 5
3rd Jul 2018, 1:19 AM
John Wells
John Wells - avatar
+ 5
You were using true to exit loop with break. While uses false to exit the loop.
3rd Jul 2018, 1:32 AM
John Wells
John Wells - avatar
+ 1
oh!!!! thank you!! Before using break, I was using OR instead of AND!
3rd Jul 2018, 1:26 AM
Konstantinos Polemis JĂșnior
Konstantinos Polemis JĂșnior - avatar
+ 1
Great! Thank you for the explanation!
3rd Jul 2018, 1:35 AM
Konstantinos Polemis JĂșnior
Konstantinos Polemis JĂșnior - avatar
0
The full code is on my profile! Thanks!
2nd Jul 2018, 11:57 PM
Konstantinos Polemis JĂșnior
Konstantinos Polemis JĂșnior - avatar