xHarbour Reference Documentation > Operator Reference xHarbour Developers Network  

--

Decrement operator (unary): Prefix / postfix decrement

Syntax

-- <Variable>
<Variable> --

Arguments

<Variable>
<Variable> is the name of a memory or field variable of Numeric or Date data type. When <Variable> is a field variable, it must be specified with an alias name or must be declared as field variable using the FIELD statement.

Description

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.

Info

See also:++, -, :=, = (compound assignment)
Category: Mathematical operators , Operators
LIB:xhb.lib
DLL:xhbdll.dll

Example

   // 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe