Python indentation

Christopher T King squirrel at WPI.EDU
Thu Jul 8 15:48:17 CEST 2004


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

Much more readable than improperly indented ifs, IMHO.




More information about the Python-list mailing list