Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #79027

Re: while loop - multiple condition

From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: while loop - multiple condition
Date 2014-10-12 20:43 -0400
Organization IISS Elusive Unicorn
References <loom.20141012T190458-947@post.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.14806.1413161032.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, 12 Oct 2014 17:08:00 +0000 (UTC), Shiva
<shivaji_tn@yahoo.com.dmarc.invalid> declaimed the following:

>Why is the second part of while condition not being checked?
>
>while ans.lower() != 'yes' or ans.lower()[0] != 'y':
>     ans = input('Do you like python?')
>
>
>My intention is if either of the conditions are true the loop should break.
>But the condition after 'or' doesn't seem to evaluate.
>
	ONE: Python uses short circuit evaluation: for an OR, the second clause
is only looked at if the first clause is FALSE (for an AND, the first
clause has to be TRUE before the second is evaluated).

	The only way for the second clause to be seen, above, is for the first
clause to be false -- that means ans IS EQUAL to "yes", but that condition
also means the first character is equal to "y".

	Applying de Morgan's (if I haven't forgotten my 37 year old college
courses)

	A not equal B OR C not equal D
converts into
	NOT (A equal B AND C equal D)

-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: while loop - multiple condition Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-12 20:43 -0400

csiph-web