Assignment Statements:
Filter:
Reference | Language

Assignment Statements

assigning values to variables

Single Assignment

A single assignment assigns the value of an expression on the right hand side to a variable on the left hand side. A single assignment is in the form:

examples:

A variable can be assigned a value at any time, including during declaration.

In some cases, chains of reassignment are useful:

Multiple Assignment

A multiple assignment statement assigns the elements of a Collection which is the result of an expression on the right hand side, to a list of variables on the left hand side. A multiple assignment statement is preceded by the symbol #. If the last variable on the left is preceded by three dots, then the entire remainder of the collection is assigned to that variable. There must be at least one variable name before the ellipsis.

The form of a multiple assignment is:

-- or --

examples:

Multiple assignment is implemented using the 'at' method and the 'copyToEnd' method. Your right hand side expression can return any object that responds to these messages.

Instance Variable Assignment

The basic syntax for setting the value of an instance variable is to use the variable's setter method which is the name of the variable with an underscore appended.

An alternative syntax is to use instance variable assignment.

This type of assignment is translated to the first form by the compiler. The two syntaxes are equivalent.

Series Assignment to an ArrayedCollection or List

There is a special syntax for doing assignments to a range of values in an ArrayedCollection or List.