[Edu-sig] strange "else" behaviour (after "for", without "if")

Andre Roberge andre.roberge at gmail.com
Mon Nov 21 20:19:24 CET 2011


The else clause in a for loop (or a while loop) should be read as "if no
break:"

André

On Mon, Nov 21, 2011 at 3:17 PM, Jurgis Pralgauskis <
jurgis.pralgauskis at gmail.com> wrote:

> Hello,
>
> does anyone know why this works without error on py 2.7?
>
> for x in [2, 5, 1]:     print x
> else:    print "nonsense"
>
> the result:
> 2
> 5
> 1
> nonsense
>
>
> my students made such "composition", and I don't know myself why :)
>
>
> --
> Jurgis Pralgauskis
> tel: 8-616 77613;
> Don't worry, be happy and make things better ;)
> http://kompiuterija.pasimokom.lt
> _______________________________________________
> Edu-sig mailing list
> Edu-sig at python.org
> http://mail.python.org/mailman/listinfo/edu-sig
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/edu-sig/attachments/20111121/e85a156d/attachment.html>


More information about the Edu-sig mailing list