BASIC or Python?

Martin Rand hsl at tcp.co.uk
Tue Jul 10 02:02:17 EDT 2001


On Tue, 10 Jul 2001 02:17:31 GMT, gerryq at indigo.ie (Gerry Quinn)
wrote:

[snip]

>In case anyone is fooled, here's an example from the tutorial at 
>www.python.org, which also has a FAQ on what Python is for:
>
>>>> for n in range(2, 10):
>..     for x in range(2, n):
>..         if n % x == 0:
>..            print n, 'equals', x, '*', n/x
>..            break
>..     else:
>..          print n, 'is a prime number'
>.. 
>
>Now some people may very well find that lovable, but I certainly don't.  
>Note how the clever language design means that the 'else' must be 
>level-indented with the 'for'.   No doubt longer programs are even more 
>fun.  The FAQ on increasing speed helpfully notes that function calls 
>are expensive...
>
Gerry, I only just bumbled into this thread; forgive me if I'm
pointing out the obvious.

Where would you choose to indent the 'else:' if you had a choice?
Presumably you're aware that levelling it with the 'if' would have a
different effect? Or were you objecting to the fact that Python has a
'for:' 'else:' construct in the first place?


--
Martin Rand
Highfield Software Ltd
mwr at highfield-software.co.uk
Phone: +44 (0)23 8025 2445
Fax:   +44 (0)23 8025 2445



More information about the Python-list mailing list