[EMAIL PROTECTED] wrote:

> On more than one occasion, I found myself wanting to use a "conditional
> loop" like this (with "Invalid syntax" error, of course):
> 
>       for i in c if <test>:
>               print i*2

Maybe there's been a PEP, don't really know...
Currently, the only sensible alternative is what you've written below:

> The available equivalent
> feels a bit awkward:
> 
>       for i in c:
>               if <test>:
>                       print i*2


This indeed doesn't look nice, especially if you've got lots of code instead of 
just 
print. An alternative which avoids double indentation is

for i in c:
        if not <test>: continue
        print i*2
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to