Possible Duplicate:
Incrementing in C++ – When to use x++ or ++x?
I’ve seen things like i++ commonly used in, say, for loops. But when people use -- instead of ++, for some reason some tend to write --i as opposed to i--.
Last time I checked, they both work (at least in JavaScript). Can someone tell me if this is so in other C-family languages, and if it is, why do some people prefer --i to i--?
I don’t believe the preference for prefix (
++i) vs. postfix (i++) varies depending on whether it’s an increment or a decrement.As for why, I prefer prefix where possible because my native language is English, which has mostly a verb-before-object structure (“eat dinner”, “drive car”), so “increment
i” or “decrementi” is more natural for me than “idecrement”. Of course, I’ll happily use postfix if I’m using the result and I need the value prior to the increment in an expression (rather than the incremented value).