An assignment statement is the simplest type of executable statement in a program. It is used to set or change the value of a datum. There are two types: the direct assignment and a set of five modifying assignments. Note these operators are part of the assignment statement syntax and cannot be used in general expressions to yield a result.
Then general for of all these has the same :-
assignstmt ::= target operator expression ;
The target is an expression that yields a datum or component of a datum that can be modified.
The operator can be the direct assignment operator ":=" or one of the modifying operators "+=", "-=", "*=", "/=" or "//=".
The target is an expression that yields a datum or component of a datum that can be modified. The target must not be declared as constant.
The expression is any expression that will be evaluated and used to modify the target datum. The type of the expression must match the type of the target.
Direct Assignment Operator
With the direct assignment the expression is evaluate and the result is used to overwrite the previous value in the target.
area := width * height;
In this example two values will be multiples and the result stored in the 'area' datum. The direct assignment may operate on datums of any type.
Modifying Assignment Operator
With the modifying assignment operator the expression will be evaluated and then the current value of the target will be modified in the appropriate way by that amount.
The '+=' will add the result to the value.
The '-=' will subtract the result from the current value.
The '*=' will multiply the current value by the result.
The '/=' will divide the current value by the result.
The '//=' is the same as above but integer division is used.
count := 10; count += 1;
After the above two statements the count will be contain the value 11. If the initial value of a datum being operator on by a modifying operator is Null then an error will be generated.
The modifying operators generally only operate on Number type data. One exception is the '+=' operator which can be used to append Text values.
The other exception is that a record can be appended to a one dimensional open array.