[Tutor] Unable to get out of loop [RESOLVING]
Ken G.
beachkidken at gmail.com
Sat Feb 27 07:36:53 EST 2016
On 02/26/2016 09:26 PM, Steven D'Aprano wrote:
> On Fri, Feb 26, 2016 at 08:30:19PM -0500, Ken G. wrote:
>
>> side = ""
>> while side != "0" or side != "1" or side != "2":
> That will only exit if side == "0", "1" and "2" **at the same time**.
> Clearly that is impossible, so the condition is always true, and the
> while loop will never end.
>
> Trying to reason about "reversed conditions" like that is hard, much
> much harder than reasoning about ordinary conditions. You should
> re-write it in terms of equality, then reverse the condition once:
>
> while side not in ("0", "1", "2):
> ...
>
>
Thanks Danny and Steven for your response. I will rewrite the code and
try again. I had no idea I opened up a can of worms and now, I am
putting them back. Thanks!
Ken
More information about the Tutor
mailing list