Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'closest': 0.09; 'exit': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:while': 0.09; '"in"': 0.16; 'message-id:@4ax.com': 0.16; 'partly': 0.16; 'range,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'recognise': 0.16; 'repetition,': 0.16; 'true:': 0.16; 'bit': 0.19; 'normally': 0.19; 'thu,': 0.19; '(the': 0.22; 'url:home': 0.24; 'looks': 0.24; 'header:X-Complaints-To:1': 0.27; 'function': 0.29; 'dec': 0.30; 'code': 0.31; 'allows': 0.31; 'this.': 0.32; 'but': 0.35; 'returning': 0.36; 'charset:us-ascii': 0.36; 'wrong': 0.37; 'being': 0.38; 'to:addr:python-list': 0.38; 'fact': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:u 10': 0.60; 'break': 0.61; 'due': 0.66; '"not': 0.84; 'subject:Extension': 0.84; 'received:108': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: Extension of while syntax Date: Fri, 12 Dec 2014 11:38:19 -0500 Organization: IISS Elusive Unicorn References: <14d2b880-3837-4267-a769-33ae7393f78b@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-108-79-216-154.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 6.00/32.1186 X-No-Archive: YES X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1418402302 news.xs4all.nl 2859 [2001:888:2000:d::a6]:47473 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:82458 On Thu, 11 Dec 2014 18:21:46 -0800 (PST), Nelson Crosby declaimed the following: >I was thinking a bit about the following pattern: > >value = get_some_value() >while value in undesired_values: > value = get_some_value() > >I've always hated code that looks like this. Partly due to the repetition, but partly also due to the fact that without being able to immediately recognise this pattern, it isn't very readable. > So what's wrong with while True: value = get_some_value() if value not in undesired_values: break Closest match to Ada loop value := get_some_value; exit when value not in undesired_values; end loop; (the "not in" may need to be a function receiving value and returning a boolean, if value can be some arbitrary item -- Ada normally only allows "in" for a range, not a list/array; though 2012 allows v1|v2|v...|vx ) -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/