Data types and Operators

Operator -- Foundation

Decrement operator (unary): subtracts one from a numeric or date value.

--<VarName>     // Prefix decrementing
<VarName>--     // Postfix decrementing
<VarName> designates any variable (including a field variable) containing a value of numeric or date data type. When <VarName>designates a field variable, either the alias operator must be used or <VarName> must be declared as a field variable in a FIELD statement.

The decrement operator is a unary operator which reduces the value of its operand by one. It subtracts the value 1 from the value of the variable <VarName> and then assigns the result to the variable <VarName>.

In evaluating an expression in which <VarName> is used, the position of the decrement operator determines when the decrementing occurs. When the decrement operator precedes the variable <VarName>(prefix notation), the value of the variable is first decremented and then the expression is evaluated. When the decrement operator follows the variable (postfix notation), the expression is first evaluated with the current value of the variable and then the value is decremented.

The variable <VarName> must contain a numeric or a date value at the time it is decremented. When it is not declared as LOCAL or STATIC or does not exist at the compile time, it is considered to be of storage class MEMVAR unless an explicit alias is used or it is declared as a field variable in a FIELD statement.

The decrement operator (--)
// This example illustrates the difference between the prefix and 
// postfix notation of the decrement operator. With the prefix 
// notation, the value in nValue is first decremented, then the 
// multiplication is performed. With the postfix notation, the 
// multiplication is performed first and then the value in nValue 
// is decremented. 

   LOCAL nValue, nResult 

   nValue  := 10 
   nResult := --nValue * 3          // prefix notation 
   ? nResult                        // result: 27 
   ? nValue                         // result: 9 

   nValue  := 10 
   nResult := nValue-- * 3          // postfix notation 
   ? nResult                        // result: 30 
   ? nValue                         // result: 9 


If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.