Python 2.4 | 7.3 The for statement

Facundo Batista facundobatista at gmail.com
Tue Mar 22 10:00:54 EST 2005


On 22 Mar 2005 06:32:38 -0800, he.dicho.que.no.quiero.spam at gmail.com
<he.dicho.que.no.quiero.spam at gmail.com> wrote:

> 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

Still, this can be acomplished with the break statement, in a more
clear way, with less variables (which implies less work for the gc and
everybody).

In your example, instead of verifying some condition and setting
leave_cond_n to True, you just check the same condition, and use
break.

.    Facundo

Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://pyar.decode.com.ar/



More information about the Python-list mailing list