# Assignment

Assignment is the technical term for storing the result of an expression in a variable, or a subscript or slice of a variable, for instance:

        x = a + b
        y[i] = ordinal(i) -- "one", "two", "three", etc
        y[i..j] = {1, 2, 3}

The previous contents of the variable, or element(s) of the subscripted or sliced variable are discarded, with any space they occupied automatically reclaimed and recycled immediately, as long as that data is not still being referenced elsewhere.
The equals symbol '=' can be used for both assignment and equality testing.
There is never any confusion because an assignment in Phix is a statement only, it cannot be used as an expression (as in C).
Alternatively and entirely optionally, you can explicitly use ":=" for assignment and "==" for equality testing.
Note: Unlike some programming languages, ':=' is not "declare and assign". The lhs must have previously been declared, and can be subscripted, so for instance "x[5] := 4" is perfectly valid.

### Assignment with operator

Similar to and instead of ":=" you can combine assignment with one of the operators: + - * / & && ||
For example, instead of:
you can say:
`mylongvarname = mylongvarname + 1`
`mylongvarname += 1`
and instead of:
you can say:
`galaxy[row][col][angle] = galaxy[row][col][angle] + 45`
`galaxy[row][col][angle] += 45`
As well as being shorter and more readable, with no need to carefully compare the left and right sides, when the left-hand-side has multiple subscripts/slices, the op= form usually executes faster as well.

### Explicit Discard

Should you want to call a function but ignore the result, invoke it as follows:

        {} = somefunc()

This syntax is a derivative of multiple assignment, explained next. As it describes,the {?} = format is also perfectly valid. Note that Euphoria allows implicit discarding of function results but Phix does not, since to put it mildly I do not think is a good idea, and more than once have been grateful for the reminder to save it somewhere.

### Multiple Assignment

It is also possible and often quite convenient to [declare and] assign several variables in one statement, eg:

        {{a,b},?,de} = {{1,2},3,{4,5}}
        -- same as:
        de = {4,5}
        b = 2
        a = 1

The sub-page takes a deep dive into the nitty-gritty, including why I put `de` first and `a` last, as well as performance considerations and out-of-order/premature referencing, which can safely be skipped on first reading.