Python indentation

Antoon Pardon apardon at forel.vub.ac.be
Mon Jul 12 07:19:50 EDT 2004


Op 2004-07-09, Mark 'Kamikaze' Hughes schreef <kamikaze at kuoi.asui.uidaho.edu>:
> Paramjit Oberoi <p_s_oberoi at hotmail.com>
> wrote on Fri, 09 Jul 2004 09:12:42 -0500:
>>>> Yes, and I would also be interested in an other proposal
>>>> that went something like:
>>>> while condition1:
>>>>   code
>>>> and while condition2:
>>>>   code
>>>> and while condition3:
>>>>   code
>> Andrew Koenig proposed this in the following email:
>> http://groups.google.com/groups?q=g:thl470833922d&dq=&hl=en&lr=&ie=UTF-8&selm=yu99isspv9mm.fsf%40europa.research.att.com
>> If link doesn't work - it was a post dated 2003-05-05 with the subject
>> "Re: PEP 315: Enhanced While Loop".  There was a fairly long thread about
>> it back then.
>
> -1.
>
>   I do occasionally write loops where I do something, test and maybe
> break, and then go on to do something else.  However, the current while
> construct does that just fine, and clearly expresses the start and end
> of the code block:
>
> linenum=1
> while True:
>     line = raw_input()
>     if not line: break  # or put on its own line, depending on taste
>     print "%05d:%s" % (linenum, line,)
>     linenum += 1
>
>   This confuses me as to where the loop starts and ends:

This confusion may be nothing more than your unfamiliary which
such a construct.

> linenum=1
> while True:
>     line = raw_input()
> and while line:
>     print "%05d:%s" % (linenum, line,)
>     linenum += 1
>
>   I rarely use post-loop condition testing even in Java where it exists
> and you can use assignment as an expression, let alone in Python.  When
> I do, an explicit if...break at the end works fine.

That is not an argument. Before instructions like while, repeat etc
existed, we could use the equivallent of an if combined with a goto
and that worked fine too.

> Any loop that's
> more than a few lines long, I usually extract into its own method.


-- 
Antoon Pardon



More information about the Python-list mailing list