Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Not intuitive? What do you think a post-decrement does do if not that?


A lot of people forget (or never knew) that the increment and decrement operators return a value as well as affecting the target variable, and that you can put what-ever you like in the iteration end control portion of a for statement as long as it returns truey/falsey.


The clever part here is that it's defined as:

for(i=4;i--;)

instead of the more common (off by one?)

for(i=4; i > 0; i--) syntax


That is clever.


I recommend reading K&R (http://en.wikipedia.org/wiki/The_C_Programming_Language) if you haven't already. It's got all sorts of elegant tricks like this. But of course it depends on very particular implementation details at times.


Don't worry, I have (hence my disbelief at the first comment). Funny we've come full circle (via e.g. Java) back to the point where that is valid code.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: