Python 2.4 | 7.3 The for statement

he.dicho.que.no.quiero.spam at gmail.com he.dicho.que.no.quiero.spam at gmail.com
Tue Mar 22 09:32:38 EST 2005


brainsucker wrote:

> Python 2.4 | 7.3 The for statement:
> -----------------------------------
>
>  for_stmt ::= "for" target_list "in" expression_list ":"
>   suite ["else" ":" suite]
>
>
> New for statement:
> ------------------
>
> for_stmt ::= "for" target_list "in" expression_list
>  [ "and" expression ] ":"
>   suite ["else" ":" suite]
>
>   ** If the expression evaluates to False before
>      entering the for, jump else.
>   ** If the expression is evaluated to False after
>      the first iteration, break.




I think that your idea is good but as others said the "and" literal
could be confusing. ¿Maybe we can use another word instead of "and"?

The for definition could be like this:

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

or some other word that clarifies the work of the expression

 leave_cond_1 = False
 leave_cond_2 = False
 mylist = [1,2,3,4,5]
 for item in mylist until leave_cond_1 or leave_cond_2:
       print item




More information about the Python-list mailing list