Difference between revisions of "Pre and Post Increment and Decrement"
Line 1: | Line 1: | ||
− | '''Array : The array object''' | + | '''Array : The array object''' |
− | |||
− | |||
<span style="color:#000000;">++x is pre-increment and --x is pre-decrement</span> | <span style="color:#000000;">++x is pre-increment and --x is pre-decrement</span> | ||
Line 17: | Line 15: | ||
<span style="color:#a52a2a;"><span style="font-size: 12px;">'''Examples'''</span></span> | <span style="color:#a52a2a;"><span style="font-size: 12px;">'''Examples'''</span></span> | ||
− | + | <source lang="javascript">number a = 1; | |
− | |||
− | |||
number b; | number b; | ||
b = ++a; | b = ++a; | ||
Line 28: | Line 24: | ||
print(a); // 1</source> | print(a); // 1</source> | ||
− | + | <source lang="javascript">number c = 3; | |
number d; | number d; | ||
d = c++; | d = c++; | ||
Line 35: | Line 31: | ||
d = c--; | d = c--; | ||
print(d); // 4 | print(d); // 4 | ||
− | print(c); // 3</source> | + | print(c); // 3</source> |
[[Category:Operators]] | [[Category:Operators]] |
Revision as of 08:51, 14 September 2011
Array : The array object
++x is pre-increment and --x is pre-decrement
x++ is post-increment and x-- is post-decrement
With ++x and --x: means x is incremented BEFORE being used.
With x++ and x--: means x is incremented AFTER being used.
Examples
number a = 1;
number b;
b = ++a;
print(b); // 2
print(a); // 2
b = --a;
print(b); // 1
print(a); // 1
number c = 3;
number d;
d = c++;
print(d); // 3
print(c); // 4
d = c--;
print(d); // 4
print(c); // 3