DataBasic Reference > DataBasic Elements > Assignment Operators

Comment on this topic

Documentation Comments

Use this form to comment on this topic. You can also provide any general observations about the Online Documentation, or request that additional information be added in a future release.

Reality V15.0 ()

Assignment Operators (DataBasic) (m618702+assignmentoperators.htm)

To

Reality

Version

Topic

Submitted by

Company

Location

Email address

Comment

 

 

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.

RealityV15.0Comment on this topic