[Tutor] while x != 'n' or 'N' or 'l' or 'L':
alan.gauld@bt.com
alan.gauld@bt.com
Wed, 6 Dec 2000 16:31:42 -0000
> The original statement:
> while x != 'n' or 'N' or 'l' or 'L':
>
> Should have been:
> while x != 'n' or x != 'N' or x != 'l' or x != 'L':
Nope, theres a thing called De Morgans law that applies
to logical expressions which says that to get the
same result you need to swap or for and, thus:
while (x != 'n') and (x != 'N') and (x != 'l') and (x != 'L'):
In your version if x is 'n' then it would not (obviously!)
be 'N' so the (x != 'N') test would be true and the
while would continue...
Alan g.