Increment
From Wikipedia, the free encyclopedia
An increment is an increase of some amount, either fixed or variable. For example one's salary may have a fixed annual increment or one based on a percentage of its current value. A decrease is called a decrement.
Incremental may also refer to gradual change, as opposed to massive, instant change.
Contents |
[edit] Use in science and technology
Incremental changes are gradual improvements as opposed to revolutionary, paradigm-breaking changes - i.e. whereas the invention of inner tube tires was only an incremental change to wheels, the invention of the combustion engine was a revolutionary change over animal-drawn vehicles.
[edit] Use in programming languages
Incrementing is of constant use in computer programming, such as in loops that iterate through a set of items one at a time.
For example, in JavaScript, which inherits the syntax from languages such as C, C++, and Java, the increment unary operator works like the following:
x++
Where the decrement operator is:
x--
In addition, the increment operator can be written both as x++ and ++x, with separate meanings. For example:
var y = ++x
is known as preincrement, shorthand for:
x = x+1 var y = x
however,
var y = x++
is known as postincrement, shorthand for:
var y = x x = x+1
--x (predecrement) instead of x-- (postdecrement) follows similar behavior.
Some languages, such as C and C++, do not specify when the increment occurs, whether immediately before (or after) use, at the beginning (or end) of the statement, or at some point in between. For this reason, referencing a variable more than once in a statement where the increment operator is used results in undefined behavior. The same code may produce different results on different compilers, different architectures, or even the same compiler with different optimization settings. For example,
int x = 0 x = x++
may result in x having either the value 0 or 1. Similarly,
int x = 0 int y = x++ + x++
may result in y having either the value 0 or 1 or even 2.
In C++, the nested increment operator is allowed but for only pre-increment and it is not applicable for the decrement operator.
Ex: int x = 0;
++(++x); is allowed but (x++)++, --(--x) or (x--)-- are not possible.
[edit] Haskell
The ++ operator is used for list concatenation in Haskell.
concat xs = foldr (++) [] xs
[edit] See also
| Look up increment in Wiktionary, the free dictionary. |

