Assignment Statements

Assignment Statements


An assignment statement in Deluge uses the assignment operator (=) to assign the result of an expression to a variable.


variable = expression;

 Compound Assignment Operators

compound assignment operator is an operator that performs a calculation and an assignment at the same time. All Deluge binary arithmetic operators (that is, the ones that work on two operands) have equivalent compound assignment operators:

+=Addition and assignment
-=Subtraction and assignment
*=Multiplication and assignment
/=Division and assignment
%=Remainder and assignment


The statement

 a += 10;

is equivalent to

a = a + 10;

Technically, an assignment is an expression, not a statement. Thus,a = 5 is an assignment expression, not an assignment statement. It becomes an assignment statement only when you add a semicolon to the end.

An assignment expression has a return value just as any other expression does; the return value is the value that’s assigned to the variable. For example, the return value of the expression a = 5 is 5. This allows you to create some interesting, but ill-advised, expressions by using assignment expressions in the middle of other expressions. For example:

int a; int b; a = (b = 3) * 2;   // a is 6, b is 3

Using assignment operators in the middle of an expression can make the expression harder to understand, so it’s not recommended.


Share this post :


Still can't find what you're looking for?

Write to us: