xHarbour Reference Documentation > Operator Reference |
Compound assignment (binary): inline operation with assignment.
<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
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
Operator | Equivalent | Inline operation |
---|---|---|
x += y | x := (x + y) | Concatenation, Addition |
x -= y | x := (x - y) | Concatenation, Subtraction |
x *= y | x := (x * y) | Multiplication |
x /= y | x := (x / y) | Modulus |
x ˆ= y | x := (x ˆ y) | Exponentiation |
Note that there is no **= compound assignment operator, but only the ˆ= operator.
See also: | %, *, **, +, ++, -, --, /, := |
Category: | Assignment operators , Mathematical operators , Operators |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// 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
http://www.xHarbour.com