You are on page 1of 1

Value of an assignment[edit]

In some programming languages, an assignment statement returns a value, while in others it


does not.
In most expression-oriented programming languages (for example, C), the assignment statement
returns the assigned value, allowing such idioms as x = y = a , in which the assignment
statement y = a returns the value of a , which is then assigned to x . In a statement such
as while ((ch = getchar()) != EOF) {…} , the return value of a function is used to control
a loop while assigning that same value to a variable.
In other programming languages, Scheme for example, the return value of an assignment is
undefined and such idioms are invalid.
In Haskell,[8] there is no variable assignment; but operations similar to assignment (like assigning
to a field of an array or a field of a mutable data structure) usually evaluate to the unit type, which
is represented as () . This type has only one possible value, therefore containing no information.
It is typically the type of an expression that is evaluated purely for its side effects.

Variant forms of assignment[edit]


Certain use patterns are very common, and thus often have special syntax to support them.
These are primarily syntactic sugar to reduce redundancy in the source code, but also assists
readers of the code in understanding the programmer's intent, and provides the compiler with a
clue to possible optimization.

Augmented assignment

You might also like