I know it's "too clever", but if I'm writing code no one else will ever see,
while (i --> 0) {
// use array[i]
}
easy to read (if not understand), and correct!It's a well-known (ish) idiom that nobody uses. It's very entertaining though, for sure. In some circles it's known as the down-to operator.
I always use unsigned values and do:
while (i-- != 0) { ... }
It's more clear than the most idiomatic way, which is to drop the explicit comparison: while (i--) { ... }
All of it is better than the clunky old for-loop syntax.This is why we never escape the cycle of rebirth.
Praise to the old gods and the new, why?!
Code like this is why i prefer human code more than llm.
Reading code should be enjoyable.
I don't think it's too clever at all. Notably it works with both signed and unsigned i. Frankly if I see anyone doing anything other than this, they're wrong.
Always.
(Hi Ken!)
[dead]
Oh I remember this from the classic SO post, but it was just presented as a funny trick. I never realized that it solves the issue mentioned in the article and there is a legitimate use-case for post-decrement in the comparison itself.
https://stackoverflow.com/questions/1642028/what-is-the-oper...