Compound Assignments

In addition to regular assignments (that is, :=), the Jade language supports compound assignments.

Syntax

Left-hand-operand assignment-operator expression;

The compound assignment operators listed in the following table are supported.

Compound Assignment Operator Assignment
+= Addition
-= Subtraction
*= Multiplication
/= Division
^= Power
%= Modulo
&= Concatenation

Description

Compound assignment operators are an extension to the := assignment operation. They provide a shorthand syntax for assigning the result of an arithmetic or concatenation operation.

Compound assignment operators perform the operation specified by the additional operator on the left and right operands, then assign the result to the left operand. The following is therefore equivalent to the above syntax.

Left-hand-operand := left-hand-operand operator (expression);

The expression is in parentheses because the additional arithmetic operation is performed on the left‑hand operand and the result of the expression, before assigning it to the left‑hand operand.

Rules

Compound assignment operators have strict rules about the types that can be used for the various operators, as follows.

Subtleties

To provide a straightforward syntax, integer division (div) and real division (/) operators have both been incorporated into the division assignment (/=) operator. The operation that gets performed depends on the type of the left‑hand operand.

This combined division assignment operator approach means that it is not possible to short‑hand a Real, Decimal, or TimeStampInterval integer division, as it always favors real division.

Example

The following demonstrates some valid compound assignment examples.

vars
    integer : Integer;
    real    : Real;
    string  : String;
begin
    integer := 6;
    integer += 94;
    integer -= 50;
    integer /= 10;
    write integer;
    real := 123.456;
    real /= 100;
    write real;
    string := "hello";
    string &= " world!";
    write string;
end;

The above example outputs the following.

5
1.23456
hello world!

2020.0.02 and higher