[Plone-IT] else nei cicli in python

Vito Falco vitofalco a gmail.com
Lun 11 Nov 2013 09:42:43 UTC


Una autentica chicca!
 grazie Yuri


2013/11/11 Yuri <yurj a alfa.it>

> Oggi ho trovato questa particolaritÓ, che non avevo mai usato:
>
>
>  The /else/ Statement Used with Loops
>
> Python supports to have an *else* statement associated with a loop
> statements.
>
>  *
>
>    If the *else* statement is used with a *for* loop, the *else*
>    statement is executed when the loop has exhausted iterating the list.
>
>  *
>
>    If the *else* statement is used with a *while* loop, the *else*
>    statement is executed when the condition becomes false.
>
>
>    Example:
>
> The following example illustrates the combination of an else statement
> with a for statement that searches for prime numbers from 10 through 20.
>
> #!/usr/bin/python
>
> for  numin  range(10,20):   #to iterate between 10 to 20
>    for  iin  range(2,num):  #to iterate on the factors of the number
>       if  num%i==  0:       #to determine the first factor
>          j=num/i#to calculate the second factor
>          print  '%d equals %d * %d'  %  (num,i,j)
>          break  #to move to the next number, the #first FOR
>    else:         # else part of the loop
>       print  num,  'is a prime number'
>
>
>
> _______________________________________________
> Plone-IT mailing list
> Plone-IT a lists.plone.org
> https://lists.plone.org/mailman/listinfo/plone-plone-it
> http://plone-regional-forums.221720.n2.nabble.com/Plone-Italy-f221721.html
>



-- 
*Vito Falco*
Webdeveloper & designer freelance, Plone enthusiast
Bari, IT
tel +39 3346330137 | skype vito80ba | twitter vito80ba
Linkedin http://it.linkedin.com/in/vitof
-------------- parte successiva --------------
Un allegato HTML Ŕ stato rimosso...
URL: <http://lists.plone.org/pipermail/plone-plone-it/attachments/20131111/1915bd9c/attachment.html>


Maggiori informazioni sulla lista Plone-IT