Go forward to Conversion.
Go backward to Assignment Ops.
Go up to Expressions.
Increment Operators
===================
"Increment operators" increase or decrease the value of a variable
by 1. You could do the same thing with an assignment operator, so the
increment operators add no power to the `awk' language; but they are
convenient abbreviations for something very common.
The operator to add 1 is written `++'. It can be used to increment
a variable either before or after taking its value.
To pre-increment a variable V, write `++V'. This adds 1 to the
value of V and that new value is also the value of this expression.
The assignment expression `V += 1' is completely equivalent.
Writing the `++' after the variable specifies post-increment. This
increments the variable value just the same; the difference is that the
value of the increment expression itself is the variable's *old* value.
Thus, if `foo' has the value 4, then the expression `foo++' has the
value 4, but it changes the value of `foo' to 5.
The post-increment `foo++' is nearly equivalent to writing `(foo +=
1) - 1'. It is not perfectly equivalent because all numbers in `awk'
are floating point: in floating point, `foo + 1 - 1' does not
necessarily equal `foo'. But the difference is minute as long as you
stick to numbers that are fairly small (less than a trillion).
Any lvalue can be incremented. Fields and array elements are
incremented just like variables. (Use `$(i++)' when you wish to do a
field reference and a variable increment at the same time. The
parentheses are necessary because of the precedence of the field
reference operator, `$'.)
The decrement operator `--' works just like `++' except that it
subtracts 1 instead of adding. Like `++', it can be used before the
lvalue to pre-decrement or after it to post-decrement.
Here is a summary of increment and decrement expressions.
`++LVALUE'
This expression increments LVALUE and the new value becomes the
value of this expression.
`LVALUE++'
This expression causes the contents of LVALUE to be incremented.
The value of the expression is the *old* value of LVALUE.
`--LVALUE'
Like `++LVALUE', but instead of adding, it subtracts. It
decrements LVALUE and delivers the value that results.
`LVALUE--'
Like `LVALUE++', but instead of adding, it subtracts. It
decrements LVALUE. The value of the expression is the *old* value
of LVALUE.