Python indentation

Antoon Pardon apardon at forel.vub.ac.be
Fri Jul 9 03:13:24 EDT 2004


Op 2004-07-08, Christopher T King schreef <squirrel at WPI.EDU>:
> On 8 Jul 2004, Antoon Pardon wrote:
>
>> Well personnaly if i have a loop with the terminating condition
>> in the middle I now have to write it like this
>> 
>> while True:
>>   code
>>   if condition: break
>>   code
>> 
>> 
>> I would prefer to indent sucu code as follows:
>> 
>> while True:
>>   code
>> if condition: break
>>   code
>> 
>> 
>> Why? because the loopbreaker is IME part of the loopstructure,
>> not an ordinary if statement in the loopbody.
>
> Then perhaps you'd be interested in PEP 315:
>
> do:
>   code
> while not condition:
>   code

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



maybe we should combine them into something like

do:
  code
and while condition1:
  code
and while condition3:
  code

> Much more readable than improperly indented ifs, IMHO.
>

Sure, but since I mostly do this in C, I use a macro
so it doens't look like an if.

-- 
Antoon Pardon



More information about the Python-list mailing list