xHarbour Reference Documentation > Operator Reference xHarbour Developers Network  

= (compound assignment)

Compound assignment (binary): inline operation with assignment.

Syntax

<Variable> += <cString>       // inline string concatenation
<Variable> += <nNumber>       // inline addition
<Variable> -= <cString>       // inline string concatenation
<Variable> -= <nNumber>       // inline subtraction
<Variable> -= <dDate>         // inline subtraction
<Variable> *= <nNumber>       // inline multiplication
<Variable> /= <nNumber>       // inline division
<Variable> %= <nNumber>       // inline modulus
<Variable> ˆ= <nNumber>       // inline exponentiation

Arguments

<Variable>
<Variable> is the name of an arbitrary variable. It must be initialized with a value of a data type valid for the inline operation.
<cString>
<cString> is a character string used in the inline operation.
<nNumber>
<nNumber> is a numeric expression used in the inline operation.
<dDate>
<dDate> is a date value used in the inline operation.

Description

A compound operator takes the value of the left operand and performs an inline operation with the value of the right operand, before it assigns the result to the left operand. Compound operators can therefore be used in expressions like the inline assignment operator.

The following table lists the operators and their equivalents:

Compound operators
OperatorEquivalentInline operation
x += yx := (x + y)Concatenation, Addition
x -= yx := (x - y)Concatenation, Subtraction
x *= yx := (x * y)Multiplication
x /= yx := (x / y)Modulus
x ˆ= yx := (x ˆ y)Exponentiation

Note that there is no **= compound assignment operator, but only the ˆ= operator.

Info

See also:%, *, **, +, ++, -, --, /, :=
Category: Assignment operators , Mathematical operators , Operators
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The  example demonstrates the results of compound operators.

   PROCEDURE Main
      LOCAL cString := "A"
      LOCAL dDate   := StoD( "20051130" )
      LOCAL nValue  := 2

      ? cString += "B "                // result: "AB "
      ? cString -= "C "                // result: "ABC  "

      ? dDate += 24                    // result: 12/24/2005

      ? (nValue ˆ= 3) - 6              // result: 2.00
      ? nValue                         // result: 8.00

      nValue ˆ= 4
      ? nValue                         // result: 4096.00

   RETURN

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