xHarbour Reference Documentation > Operator Reference |
Decrement operator (unary): Prefix / postfix decrement
-- <Variable> <Variable> --
The decrement operator decreases the value of its operand by one. When used in an expression, the position of the operator is important for the result of the expression.
When the operator appears to the left of the operand (prefix notation), the operand's value is first decremented and then used in the expression.
When the operator appears to the right of the operand (postfix notation), the operand's value is first used in the expression and then decremented.
See also: | ++, -, :=, = (compound assignment) |
Category: | Mathematical operators , Operators |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example demonstrates the use of the -- operator and // outlines the importance of prefix and postfix notation. PROCEDURE Main LOCAL nValue1 := 0 LOCAL nValue2 ? nValue1 -- // result: 0 ? nValue1 // result: -1 ? -- nValue1 // result: -2 ? nValue1 // result: -2 nValue2 := -- nValue1 ? nValue1 // result: -3 ? nvalue2 // result: -3 nValue2 := nValue1 -- ? nValue1 // result: -4 ? nvalue2 // result: -3 RETURN
http://www.xHarbour.com