(May-31-2020, 03:35 PM)Yoriz Wrote:button1_pressed = True button2_pressed = True button3_pressed = True button2_is_not_pressed = True while button1_pressed and button2_pressed: print('do some') # this only happens if both the above are True while button3_pressed: print('do some2') # theis only happens if button3_pressed is True if button2_is_not_pressed: break # this only breaks the inner while loop break # added an extra break else it would just be stuck in an endless outer loopThe following conditions nothing will happen
Output:do some do some2
button1_pressed = False button2_pressed = True button3_pressed = True button2_is_not_pressed = True while button1_pressed and button2_pressed: print('do some') # this only happens if both the above are True while button3_pressed: print('do some2') # theis only happens if button3_pressed is True if button2_is_not_pressed: break # this only breaks the inner while loop break # added an extra break else it would just be stuck in an endless loop
Output:button1_pressed
andbutton2_pressed
must be returning True even though you think they should not be.
I really apreciate your help... but imagine this situation:
1 - user press
button1
and button2
then press button3
Its ok to me "do some 2"
2 - user press
button2
and button1
then press button3
Its ok to me "do some 2"
but
3 - user press
button3
before button1
and button2
Its not ok to "do some2", I need just to "do some"
Mate, I should have mentioned that this whole code is inside a Main loop. Im sorry!!
So.. I Thinks to test should be like this:
button1_pressed = True button2_pressed = True button3_pressed = True button2_is_not_pressed = True while True: while button1_pressed and button2_pressed: print('do some') # this only happens if both the above are True while button3_pressed: print('do some2') # theis only happens if button3_pressed is True if button2_is_not_pressed: break # this only breaks the inner while loop break # added an extra break else it would just be stuck in an endless outer loop