[Python-ideas] Control Flow - Never Executed Loop Body

Michel Desmoulin desmoulinmichel at gmail.com
Mon Mar 21 14:37:56 EDT 2016



Le 21/03/2016 17:34, Chris Barker a écrit :
> I've taught enough and I'm sure everyone else here has too, to know that
> the "else" in a for loop in non-intuitive to a lot of folks. And maybe a
> different keyword would have been clearer. But it is what it is, could
> we keep this discussion to the proposed addition?

+1 I would love "else" semantics to be changed as well, but we can't.

What about:

for x in stuff:
    foo(x)
or:
    bar()

It's a bit weird when you read it the first time, but:

- It conveys pretty well the intent.
- While it still closes to the original "or" semantics, you can't
confuse this syntax with the other syntax for "or".
- I can't think of a use case where the parser can find that ambigious.
- It's short.



> 
> -CHB
> 
> 
> 
> -- 
> 
> Christopher Barker, Ph.D.
> Oceanographer
> 
> Emergency Response Division
> NOAA/NOS/OR&R            (206) 526-6959   voice
> 7600 Sand Point Way NE   (206) 526-6329   fax
> Seattle, WA  98115       (206) 526-6317   main reception
> 
> Chris.Barker at noaa.gov <mailto:Chris.Barker at noaa.gov>
> 
> 
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
> 


More information about the Python-ideas mailing list