Operator ++ Foundation

Increment operators (unary): increase numeric or date value by one.

Syntax
++<VarName>     // Prefix incrementing
<VarName>++     // Postfix incrementing
Parameters
<VarName>
<VarName> designates any variable type including a field variable, member variable, or array element 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.
Description

The increment operator is a unary operator which increments the value of its operand. It first adds the value 1 to the value of the variable <VarName> and then assigns the result to the variable.

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

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

Examples
The increment operator (++)
// This example illustrates the difference between the prefix and 
// postfix notation of the increment operator. With the prefix 
// notation the value is first incremented then multiplication 
// is performed. With postfix notation the multiplication 
// is performed first, then the value in nValue is incremented. 

PROCEDURE Main 
   LOCAL nValue, nResult 

   nValue  := 10 
   nResult := ++nValue * 3          // prefix notation 
   ? nResult                        // result: 33 
   ? nValue                         // result: 11 

   nValue  := 10 
   nResult := nValue++ * 3          // postfix notation 
   ? nResult                        // result: 30 
   ? nValue                         // result: 11 

RETURN 
Feedback

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.