Dan Perl wrote:
I can't say that is not part of the reason, but the example in the OP is a clear illustration of cases where something like an increment/decrement operator would be very useful.

The OP didn't show how he was using the "while (n--)" at all, so it can hardly be a clear illustration of how it's useful. In fact, it's even possible it was entirely unnecessary in the original code... at this point I'd be really interested in seeing just what code is inside the "while" statement, and possibly what follows it (if the following code relies on the value of "n").

OTOH, I was thinking of saying in my previous posting that I prefer
for n in range(start, 0, -1):
to
n = start
while (n--)
I think that the first form is more readable, although that may be just me. I would actually even prefer the 'for' statement in C to the 'while' statement:
for (n=start; n<=0; n--)

I'm not sure if it's just picking nits, but I'd like to point out that neither of your alternatives is actually equivalent to the while (n--) form... nor was Jeff Shannon's attempt (in that case it leaves the loop with n equal to 0, not -1).

The fact that it's so easy to get confused with post-decrement
is perhaps an excellent reason to keep it out of Python.

-Peter
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to