Why do people use i = i + 1 instead of i++?

26,111

Solution 1

Not all languages have ++ operator (python, for one)... Probably these people come from a background in one of those languages. Also some people feel that i++ is not very clear, especially since some languages treat i++ and ++i differently.

Solution 2

Personal preference and style.

Solution 3

Prevents excess craftiness. At least that is what Crockford says.

Solution 4

i = i + 1 is easier to decode in English. i++ although totally correct doesn't translate well when beginners are reading the code. The programmer was possibly trying to make their code more readable by beginners, or perhaps just not trying to be overly concerned about syntax. There's no good reason to use one over the other.

Share:
26,111
David G
Author by

David G

[email protected]

Updated on July 09, 2022

Comments

  • David G
    David G almost 2 years

    I've seen that in a number of loops and increments. Instead of doing i++ they do i += 1. Why is this?