[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
--
Decrement--unary (Mathematical)
------------------------------------------------------------------------------
Syntax
--<idVar> (prefix decrement)
<idVar>-- (postfix decrement)
Type
Date, numeric
Operands
<idVar> is any valid CA-Clipper identifier, including a field
variable. If <idVar> is a field, you must reference it prefaced with an
alias or declare it with the FIELD statement.
In addition, you must initialize <idVar> to a value before performing
the decrement operation, and it must be either numeric or date data
type.
Description
The decrement operator (--) decreases the value of its operand by one.
This operator subtracts one from the value of <idVar> and assigns the
new value to <idVar>.
The -- operator can appear before or after <idVar>. Specifying the
operator before <idVar> decrements and assigns the value before the
value is used. This is called prefix notation, and it is the most
common usage. Specifying the operator after <idVar> decrements and
assigns the value after it is used. This is postfix notation. Stated
differently, postfix notation delays the assignment portion of the
operation until the rest of the expression is evaluated, and prefix
notation gives the assignment precedence over all other operations in
the expression.
If the reference to <idVar> is ambiguous (i.e., not declared at compile
time and not explicitly qualified with an alias), <idVar> is always
assumed to be MEMVAR. You can assign field variables by declaring the
field variable name in a FIELD statement or by referring to the field
name prefaced by the FIELD-> alias or by the name of the work area.
Examples
. In this example of the postfix decrement operator the
assignment takes place before the original variable is decremented,
thus the two values are not the same when queried:
nValue := 1
nNewValue := nValue--
? nNewValue // Result: 1
? nValue // Result: 0
. In this example, the prefix decrement operator decreases the
first operand of the multiplication by one, making its value 9.
Then, the assignment of this new value to the nValue variable takes
place before the rest of the expression is evaluated. Thus, the new
value is used to perform the multiplication operation, and the result
of 9 * 9 is 81.
nValue := 10
? --nValue * nValue // Result: 81
? nValue // Result: 9
See Also:
++
-
:=
= (compound)
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson