Re: Is this PEP-able? fwhile

Discussion in 'Python' started by Fábio Santos, Jun 24, 2013.

  1. On Mon, Jun 24, 2013 at 8:52 PM, <> 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'.
    >
    > (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 thisup
    > 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.
    >


    I can see where you are coming from, but this is probably not going to
    happen. The "and" keyword is also

    Also, the (amazing) python devs are concerned with overcomplicating
    the language syntax, which is bad for: newbies, other implementations
    of the language, and code readability. The syntax doesn't seem too
    obvious, and there is a new keyword, "fwhile".

    This can probably be best achieved by adding to the existing for loop,
    so maybe taking advantage of the existing for...if syntax and adding
    for...while would be a better idea?

    So, maybe:

    for x in y while cond:

    And for list/set/dict comprehensions and generator expressions:

    [x for x in range(123) while cond]

    Just maybe.

    --
    Fábio Santos
     
    Fábio Santos, Jun 24, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    119
    Chris Angelico
    Jun 26, 2013
  2. Ian Kelly

    Re: Is this PEP-able? fwhile

    Ian Kelly, Jun 24, 2013, in forum: Python
    Replies:
    7
    Views:
    122
  3. Ian Kelly

    Re: Is this PEP-able? fwhile

    Ian Kelly, Jun 24, 2013, in forum: Python
    Replies:
    0
    Views:
    106
    Ian Kelly
    Jun 24, 2013
  4. Joshua Landau

    Re: Is this PEP-able? fwhile

    Joshua Landau, Jun 24, 2013, in forum: Python
    Replies:
    0
    Views:
    110
    Joshua Landau
    Jun 24, 2013
  5. Replies:
    0
    Views:
    93
Loading...

Share This Page