# Assignment Operators

**Applies To:** Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012

An assignment changes the contents of a variable or field.

The X++ assignment operators are shown in the following table.

Operator |
Description |
---|---|

= |
Assigns the expression on the right of the equal sign to the variable on the left. |

+= |
Assigns the variable on the left the current variable value plus the expression on the right. |

++ |
Increments the variable by one. |

-= |
Assigns the variable on the left the current variable value minus the expression on the right. |

-- |
Decrements the variable by one. |

Note

There is no difference between prefixed and postfixed operators.

## Examples

The examples in the following table assume that the initial value of i is 1.

Assignment |
Example |
Description |
---|---|---|

= |
i = i + 1; |
i is assigned the value of i, plus 1. i = 2. |

+= |
i += 1; |
i is assigned the value of i, plus 1. i = 2 (i = i + 1). |

++ |
i++; ++i; |
i is incremented by 1, and then by 1 again in the second statement. The final value of i is 3. |

-= |
i -= 1; |
i is assigned the value of i minus 1. i = 0 (i = i - 1). |

-- |
--i; i--; |
i is decremented by 1, and then by 1 again in the second statement. The final value of i is -1. |

## See also

**Announcements:** New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.