Skip to main content
edited title
Link
Seggan
  • 3.1k
  • 10
  • 44

Why add an increment/decrement operator when compound assignnmentsassignments exist?

Became Hot Network Question
added 71 characters in body
Source Link
Seggan
  • 3.1k
  • 10
  • 44

Many languages have compound assignment statements, for example +=. However, for the common task of adding or subtracting 1 from a variable some languages (mostly those close to C) have additional ++ and -- operators. For example, x += 1 can be written as x++ in these languages. Some languages decide not to have these operators. This can make some sense, as there is already a short way to increment something. Why would you add an increment/decrement operator when you have compound assignments? For completeness, I'll allow arguments for the other position as well.

Many languages have compound assignment statements, for example +=. However, for the common task of adding or subtracting 1 from a variable some languages (mostly those close to C) have additional ++ and -- operators. For example, x += 1 can be written as x++ in these languages. Some languages decide not to have these operators. This can make some sense, as there is already a short way to increment something. Why would you add an increment/decrement operator when you have compound assignments?

Many languages have compound assignment statements, for example +=. However, for the common task of adding or subtracting 1 from a variable some languages (mostly those close to C) have additional ++ and -- operators. For example, x += 1 can be written as x++ in these languages. Some languages decide not to have these operators. This can make some sense, as there is already a short way to increment something. Why would you add an increment/decrement operator when you have compound assignments? For completeness, I'll allow arguments for the other position as well.

Source Link
Seggan
  • 3.1k
  • 10
  • 44

Why add an increment/decrement operator when compound assignnments exist?

Many languages have compound assignment statements, for example +=. However, for the common task of adding or subtracting 1 from a variable some languages (mostly those close to C) have additional ++ and -- operators. For example, x += 1 can be written as x++ in these languages. Some languages decide not to have these operators. This can make some sense, as there is already a short way to increment something. Why would you add an increment/decrement operator when you have compound assignments?