Re: Is this PEP-able? fwhile

Discussion in 'Python' started by Chris Angelico, Jun 24, 2013.

  1. On Tue, Jun 25, 2013 at 8:43 AM, Ian Kelly <> wrote:
    > On Mon, Jun 24, 2013 at 4:41 PM, Fábio Santos <> wrote:
    >>
    >> On 24 Jun 2013 22:29, "Ian Kelly" <> wrote:
    >>>
    >>> On Mon, Jun 24, 2013 at 2:34 PM, Fábio Santos <>
    >>> wrote:
    >>> > 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?
    >>>
    >>> The for...if syntax only exists for comprehensions and generators. If
    >>> we're going to add for...while for loops, then we might as well go
    >>> ahead and add for...if loops there as well.
    >>>
    >>> That said, I do like this syntax better than "fwhile".

    >>
    >> Good point. Still, I don't see why for..if doesn't exist in for loops
    >> anyway. It may be lack of foresight, but I don't understand why at all.

    >
    > Because it adds more syntax to learn when learning the language, it
    > introduces more maintenance overhead, and it offers no clear benefit
    > over simply nesting an if inside a for.


    In more free-form languages, I implement this by simply omitting a line-break:

    for (int i=0;i<num_whatevers;++i) if (whatever.flag)
    {
    do_stuff;
    }

    Python could afford to lose a little rigidity here rather than gain
    actual new syntax:

    for i in range(10): if i%3:
    print(i)

    And there you are, the for-if "filtered iteration" model, just by
    relaxing one rule.

    ChrisA
    Chris Angelico, 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:
    98
    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:
    104
  3. Ian Kelly

    Re: Is this PEP-able? fwhile

    Ian Kelly, Jun 24, 2013, in forum: Python
    Replies:
    0
    Views:
    92
    Ian Kelly
    Jun 24, 2013
  4. Fábio Santos

    Re: Is this PEP-able? fwhile

    Fábio Santos, Jun 24, 2013, in forum: Python
    Replies:
    0
    Views:
    98
    Fábio Santos
    Jun 24, 2013
  5. Joshua Landau

    Re: Is this PEP-able? fwhile

    Joshua Landau, Jun 24, 2013, in forum: Python
    Replies:
    0
    Views:
    95
    Joshua Landau
    Jun 24, 2013
Loading...

Share This Page