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


Groups > comp.lang.python > #49070

Is this PEP-able? fwhile

Subject Is this PEP-able? fwhile
From jimjhb@aol.com
Date 2013-06-24 15:52 -0400
Newsgroups comp.lang.python
Message-ID <mailman.3757.1372103911.3114.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

Syntax:


fwhile X in ListY and conditionZ:


The following would actually exactly as:  for X in ListY:


fwhile X in ListY and True:


fwhile would act much like 'for', but would stop if the condition after the 'and' is no longer True.


The motivation is to be able to make use of all the great aspects of the python 'for' (no indexing or explict
end condition check, etc.) and at the same time avoiding a 'break' from the 'for'.  


(NOTE:  Many people are being taught to avoid 'break' and 'continue' at all costs, so they instead convert
the clean 'for' into a less-clean 'while'.  Or they just let the 'for' run out.  You can argue against this teaching
(at least for Python) but that doesn't mean it's not prevalent and prevailing.)


[People who avoid the 'break' by functionalizing an inner portion of the loop are just kidding themselves and making
their own code worse, IMO.]


I'm not super familiar with CPython, but I'm pretty sure I could get this up and working without too much effort.
The mandatory 'and' makes sense because 'or' would hold the end value valid (weird) and not accomplish much.
The condition itself could of course have multiple parts to it, including 'or's.


It's possible the name 'fwhile' is not optimal, but that shouldn't affect the overall merit/non-merit of the concept.


Comments and Questions welcome.


Thanks.  

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


Thread

Is this PEP-able?   fwhile jimjhb@aol.com - 2013-06-24 15:52 -0400
  Re: Is this PEP-able?   fwhile Neil Hodgson <nhodgson@iinet.net.au> - 2013-06-25 17:20 +1000
    Re: Is this PEP-able?   fwhile Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-06-25 20:47 -0400
    Re: Is this PEP-able? fwhile Chris Angelico <rosuav@gmail.com> - 2013-06-26 17:40 +1000

csiph-web