Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- CA-Clipper 5.2 . The Guide To CA-Clippe - <b>= (compound assign)</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 = (compound assign)
 Compound assignment--binary                     (Assignment)
------------------------------------------------------------------------------
 Syntax


     <idVar>  += <cString>         (concatenation)
     <idVar>  += <nNumber>         (addition)
     <idVar>  -= <cString>         (concatenation)
     <idVar>  -= <nNumber>         (subtraction)
     <idVar>  -= <dDate>           (subtraction)
     <idVar>  *= <nNumber>         (multiplication)
     <idVar>  /= <nNumber>         (division)
     <idVar>  %= <nNumber>         (modulus)
     <idVar>  ^= <nNumber>         (exponentiation)

 Type

     Character, date, memo, numeric

 Operands

     <idVar> is a variable identifier of any storage class, including a
     field variable.  The variable must be initialized to a value before
     performing the operation.

     If the reference to <idVar> is ambiguous (i.e., not declared at compile
     time and not explicitly qualified with an alias), <idVar> is assumed to
     be MEMVAR.  You can assign field variables by declaring the field
     variable name in a FIELD statement or referring to the field name
     prefaced by the FIELD-> alias or the name of the work area.

     <cString> is the character string used in the operation with
     <idVar>.

     <nNumber> is the numeric expression used in the operation with
     <idVar>.

     <dDate> is the date value used in the operation with <idVar>.

 Description

     In addition to the simple and inline assignment operators (= and :=),
     there are a series of compound assignment operators that perform an
     operation then assign a value.  They have the form:

     <idVar> <operator>= <exp>

     Each compound assignment expression is equivalent to the assignment
     expression:

     <idVar> := ( <idVar> <operator> <exp> )

     For each data type that supports an operator, the compound assignment
     operator performs the same operation before performing the assignment
     operation.  The  following table details all of the compound operators:

     Compound Operators
     ------------------------------------------------------------------------
     Operator  Defined as     Operations
     ------------------------------------------------------------------------
     a += b    a := (a + b)   concatenation, addition
     a -= b    a := (a - b)   concatenation, subtraction
     a *= b    a := (a * b)   multiplication
     a /= b    a := (a / b)   division
     a %= b    a := (a % b)   modulus
     a ^= b    a := (a ^ b)   exponentiation
     ------------------------------------------------------------------------

     Note:  The exponentiation operator (**) does not have a
     corresponding compound assignment operator.  The exponentiation compound
     assignment operator is ^=.

     Since the compound assignment operators are based on the inline
     assignment  operator (:=), the operation returns the result of its
     operation as the value of the expression.  This means you can use these
     operators within expressions just like the inline assignment  operator
     (:=).

 Examples

     .  These examples use the compound addition and concatenation
        assignment operator:

        // Character (concatenation)
        LOCAL cString := "Hello"
        ? cString += " there"               // Result: "Hello there"

        // Date (addition)
        LOCAL dDate := CTOD("12/12/90")
        dDate += 12                         // Result: 12/24/90

        // Numeric (addition)
        LOCAL nValue := 10
        ? SQRT(nValue += 15)                // Result:  5
        ? nValue                            // Result: 25

     .  These examples use the compound subtraction and concatenation
        assignment operator:

        // Character (concatenation)
        LOCAL cString := "Hello   "
        ? cString -= "There"                // Result: HelloThere

        // Date (subtraction)
        LOCAL dDate := CTOD("12/24/90")
        dDate -= 12                         // Result: 12/12/90

        // Numeric (subtraction)
        LOCAL nValue := 10
        ? newValue := (nValue -= 5) ** 2    // Result: 25
        ? nValue                            // Result:  5

     .  This example uses the compound multiplication assignment
        operator:

        LOCAL nValue := 10
        ? newValue := (nValue *= 5) + 100   // Result: 150
        ? nValue                            // Result:  50

     .  This example uses the compound division assignment operator:

        LOCAL nValue := 10
        ? newValue := (nValue /= 5) + 100   // Result: 102
        ? nValue                            // Result:   2

     .  This example uses the compound modulus assignment operator:

        LOCAL nValue := 10
        ? newValue := (nValue %= 4) * 100   // Result: 200
        ? nValue                            // Result:   2

     .  This example uses the compound exponentiation assignment
        operator:

        LOCAL nValue := 10
        ? newValue := (nValue ^= 3) + 50    // Result: 1050
        ? nValue                            // Result: 1000

See Also: % * ** + ++ - -- / :=

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson