aboutsummaryrefslogtreecommitdiffstats
path: root/source/arduino/increment.rst
blob: f9e87c98612c5d06df9b0eb2bc8d6324f06ecc6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
.. _arduino-increment:

++ (increment) / -- (decrement)
===============================

Description
-----------

Increment or decrement a variable



Syntax
------

::

    x++;  // increment x by one and returns the old value of x
    ++x;  // increment x by one and returns the new value of x
    
    x-- ;   // decrement x by one and returns the old value of x 
    --x ;   // decrement x by one and returns the new value of x  



Parameters
----------

x: an integer or long (possibly unsigned)



Returns
-------

The original or newly incremented / decremented value of the
variable.



Examples
--------

::

    x = 2;
    y = ++x;      // x now contains 3, y contains 3
    y = x--;      // x contains 2 again, y still contains 3 



See also
--------

`+= <http://arduino.cc/en/Reference/Arithmetic>`_
`-= <http://arduino.cc/en/Reference/Arithmetic>`_