[Python-ideas] for/else syntax

Ron Adam rrr at ronadam.com
Mon Oct 5 01:54:27 CEST 2009



Stephen J. Turnbull wrote:
> Ron Adam writes:
> 
>  > All good points.  I need another cup of coffee. ;-)
>  > 
>  > There may be some obscure exception to the break-else pattern but I can't 
>  > think of any at the moment.
> 
> May I suggest reading my posts.  I've made at least two attempts at
> obscure exceptions and been corrected within minutes every time.  At
> least you can avoid those! :-)


I'm not even going to try. :-)


I looked at the grammer for each of the items in question and am wondering 
if that could be improved in any way so that they indicate how break and 
continue are used in loops.



Here's the current grammer for Python 3.0 loops.  Break and Continue are 
next to each other but no where near for and while in the documentation.


while_stmt ::=  "while" expression ":" suite
                 ["else" ":" suite]

for_stmt ::=  "for" target_list "in" expression_list ":" suite
               ["else" ":" suite]

break_stmt ::=  "break"

continue_stmt ::=  "continue"


Cheers,
    Ron



More information about the Python-ideas mailing list