Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #49101
| References | <8D03F2B8CF0E7BE-1864-1796B@webmail-m103.sysops.aol.com> <CAA=1kxR65wqgQWQJaLvP2yx_XacEMsHiFs40rPW1UbFXYpnytA@mail.gmail.com> <CALwzidnADsCdNmfFsLChVq7bt9G87Rsr1DsD1M-jNmzqQ2Z0eA@mail.gmail.com> <CAA=1kxR2JU7tbNdr9smZd9=Cy-vSCwoaAzwM=6LiAZ3edzrF8A@mail.gmail.com> <CALwzid=4_dicyJ4RAFZ=vAXMTkvPqiauWoyfqjr7frFnaEXatA@mail.gmail.com> |
|---|---|
| Date | 2013-06-25 08:50 +1000 |
| Subject | Re: Is this PEP-able? fwhile |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3782.1372114251.3114.python-list@python.org> (permalink) |
On Tue, Jun 25, 2013 at 8:43 AM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> On Mon, Jun 24, 2013 at 4:41 PM, Fábio Santos <fabiosantosart@gmail.com> wrote:
>>
>> On 24 Jun 2013 22:29, "Ian Kelly" <ian.g.kelly@gmail.com> wrote:
>>>
>>> On Mon, Jun 24, 2013 at 2:34 PM, Fábio Santos <fabiosantosart@gmail.com>
>>> 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[i].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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Is this PEP-able? fwhile Chris Angelico <rosuav@gmail.com> - 2013-06-25 08:50 +1000
csiph-web