Assignment (computer Science) - Value of An Assignment

Value of An Assignment

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 (f = read) {}, 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, 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 unit, the value of the unit type, which is typically the type of an expression that is evaluated purely for its side effects.

Read more about this topic:  Assignment (computer Science)