Assignment Operators

In addition to the normal = operator, DataBasic provides a number of assignment operators that provide shortcuts by combining assignment with some other operation. For example, expressions such as

I = I + 2

in which the left-hand side is repeated on the right, can be written

I += 2

The table below lists the supported assignment operators.

Operator

Example

Equivalent

+=

A += B

A = A + B

-=

A -= B

A = A - B

*=

A *= B

A = A * B

/=

A /= B

A = A / B

:=

A := B

A = A : B

Note that the right-hand side of the expression is computed before the operation is carried out, so

X *= Y + 1

is equivalent to

X = X * (Y + 1)

rather than

X = X * Y + 1

In addition to conciseness, assignment operators can make the code easier to understand. For example,

A(X,Y)<M,N,P>[G,H] = A(X,Y)<M,N,P>[G,H] : B

can be re-written as

A(X,Y)<M,N,P>[G,H] := B

with the benefit that the reader does not have to carefully check that two long expressions are in fact the same, or to wonder why they are not.