Compound Assignment Operators (+=, -=, *=, /=, and %=): x += 1; is the same as writing x = x + 1; : Arithmetic Operators « Language « Flash / Flex / ActionScript






Compound Assignment Operators (+=, -=, *=, /=, and %=): x += 1; is the same as writing x = x + 1;

 

package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){

        var x:Number = 0;
        
        x += 5; // x = 5
        trace(x);
        
        x -= 3; // x = 2
        trace(x);
        x *= 3; // x = 6
        trace(x);
        x /= 2; // x = 3
        trace(x);
        x %= 3; // x = 0
        trace(x);
    }
  }
}

        








Related examples in the same category

1.Arithmetic Operators in Actionscript
2.Assignment Operators
3.myVariable += 6; is the shorthand version of the following: myVariable = myVariable + 6;
4.myVariable *= 6; is the same as: myVariable = myVariable * 6;
5.Using Mathematical Operators: prefix and postfix
6.Modulo (%)
7.Increment (++) and Decrement ( -- )