Recent Changes - Search:

* PCAN

* Phix

edit SideBar

AssignmentWithOperator

Index | Core Language | Statements | Assignment | Assignment with Operator

Assignment with Operator

Phix also provides some additional forms of the assignment statement.

To save typing, and to make your code a bit neater, you can combine assignment with one of the operators:

         + - / * &

For example, instead of saying:

   mylongvarname = mylongvarname + 1

You can say:

   mylongvarname += 1

Instead of saying:

   galaxy[q_row][q_col][q_size] = galaxy[q_row][q_col][q_size] * 10

You can say:

   galaxy[q_row][q_col][q_size] *= 10

and instead of saying:

   accounts[start..finish] = accounts[start..finish] / 10

You can say:

   accounts[start..finish] /= 10

In general, whenever you have an assignment of the form:

    <b><i>left-hand-side = left-hand-side op expression</i></b>

You can say:

    <b><i>left-hand-side op= expression</i></b>

where op is one of:    +   -   *   /   &

When the left-hand-side contains multiple subscripts/slices, the op= form will usually execute faster than the longer form. When you get used to it, you may find the op= form to be slightly more readable than the long form, since you do not have to visually compare the left-hand-side against the copy of itself on the right side.

Note the explicit assignment ':=' operator does not have any assignment with operator forms since the latter are already explicit assignment operations anyway.

< Assignment | Index | Explicit Discard >

Edit - History - Print - Recent Changes - Search
Page last modified on April 16, 2026, at 09:14 PM