Is this PEP-able? fwhile

Ian Kelly ian.g.kelly at gmail.com
Mon Jun 24 16:12:04 EDT 2013


On Mon, Jun 24, 2013 at 1:52 PM,  <jimjhb at aol.com> wrote:
> 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'.

I would advocate using the break myself.  Another alternative is this:

for X in itertools.takewhile(lambda X: conditionZ, ListY):
    ...



More information about the Python-list mailing list