[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
5.8 Increment and decrement operators
If you like the ‘++’, ‘+=’ etc operators, rejoice! Octave includes the C-like increment and decrement operators ‘++’ and ‘--’ in both their prefix and postfix forms, in addition to ‘+=’, ‘-=’, ‘*=’, ‘/=’, ‘^=’, ‘.*=’, ‘./=’, and ‘.^=’.
For example, to pre-increment the variable x, you would write
++x
. This would add one to x and then return the new
value of x as the result of the expression. It is exactly the
same as the expression x = x + 1
.
To post-increment a variable x, you would write x++
.
This adds one to the variable x, but returns the value that
x had prior to incrementing it. For example, if x is equal
to 2, the result of the expression x++
is 2, and the new
value of x is 3.
For matrix and vector arguments, the increment and decrement operators work on each element of the operand.