Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Rob Gaddi Newsgroups: comp.lang.python Subject: Re: while loop - multiple condition Date: Mon, 13 Oct 2014 09:12:48 -0700 Organization: Highland Technology, Inc. Lines: 18 Message-ID: <20141013091248.1ffd94a0@rg.highlandtechnology.com> References: <878uklcd3r.fsf@elektro.pacujo.net> <543b0706$0$13005$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Injection-Info: mx02.eternal-september.org; posting-host="e1074427d63fe1fd927d8970bf85e44c"; logging-data="31525"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19OxInKzG+5vKHyRAGNHail" X-Newsreader: Claws Mail 3.9.3 (GTK+ 2.24.23; x86_64-pc-linux-gnu) Cancel-Lock: sha1:7Od0dKSueMN372h/ZLLn0CfL5ak= Xref: csiph.com comp.lang.python:79052 On Mon, 13 Oct 2014 09:56:02 +1100 Steven D'Aprano wrote: > > When you have multiple clauses in the condition, it's easier to reason about > them if you write the clauses as positive statements rather than negative > statements, that is, "something is true" rather than "something is not > true", and then use `not` to reverse it if you want to loop *until* the > overall condition is true. > I was just explaining this concept to a young pup the other day. De Morgan's lets you say that (not (p and q)) == ((not p) or (not q)), but the positive logic flavor is substantially less error-prone. People are fundamentally not as good at thinking about inverted logic. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix.