June 13, 2009
Posted by Clinton Montague
What does the += operator do?
The += operator is a simplified way of writing I want to increase the variable by a certain value. It’s called the addition-assignment operator.
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | $i = 10; $i+=1; echo $i; // outputs 11; $i = 10; $i+=5; echo $i; // outputs 15 $i=10; $i+= -10; echo $i; // output 0 (since 10 + (-10) is the same as 10-10); $i=10; $i+=$i; echo $i; // output 20; |
Find out more
- MSDN page about the addition assignment for JScript
- Google search for “addition-assignment”
- A post by me: Operator precedence – what does
(i=1)*i-- - --i*(i=-3)*i++ + ++iequal and why? (not for beginners) - A similar FQG – What does the -= operator do?










1 Comments
September 20, 2011
Call me wind bceuase I am absolutely blown away.
Leave a comment