+=
Operator
Adds a number to a variable, or causes concatenation with a string and a variable, then changes the variable to the result.
Syntax
variable += expression
Parts
variable
- A numeric or string variable.
expression
- An expression with a data type compatible with
variable
.
Instructions
The two statements that follow operate the same.
variable += expression
variable = variable + expression
The element on the left side of +=
can be a scalar variable, a property, or an element of an array.
A property cannot have the modifier @ReadOnly
.
+=
adds the numeric value on its right side to the variable or property on its left side.
Then it changes the variable or property on its left side to the result.
You can also use +=
to concatenate the string value on its right side to the variable or property on its left side.
Then it changes the variable or property no differently.
Note:
We recommend that you always use &=
if you know that the values are strings.
Examples
Numeric
x = 30
x += 12
x |
42 |
---|
String
x$ = "Hello"
x$ += " world"
x$ |
"Hello world" |
---|