+ 3

what does x-=2 mean?

29th Nov 2016, 7:20 AM
BookishBookworm
BookishBookworm - avatar
8 Respostas
+ 7
it means x=x-2;
29th Nov 2016, 7:26 AM
Rohan Yadav
Rohan Yadav - avatar
+ 3
It actually a shorthand method of writing x = x - 2. It holds good with other arithmatical operators too.
2nd Dec 2016, 2:45 AM
Sampreet Gaonkar
+ 2
Like Rohan Yadav said just subtract 2 from x and then reassign it to x so that the value of x becomes 2 less than what it was before. In a loop it will continue decreasing the value over each iteration until a condition is met and the loop is dropped out of.
20th Dec 2016, 3:09 AM
Matt Roberts
Matt Roberts - avatar
+ 2
Yes, it's the sort hand for. x = x-2 you can also use: x += 2. for addition x *= 2. for multiplication x /= 2. for division x ℅=2. for modulus x **=2. for power x^2
4th Feb 2017, 12:38 PM
Mohit Goyal
Mohit Goyal - avatar
+ 1
is it a condition for a loop? If yes the loop will stop when x is 0.
29th Nov 2016, 10:36 AM
‎ɐısıօլɐ
‎ɐısıօլɐ - avatar
+ 1
x = x-2
21st Feb 2017, 9:23 PM
Mohit Jain
Mohit Jain - avatar
0
+Rohan Yadav, does that mean that when the outputed number-x equals 2, the loop will stop?
29th Nov 2016, 7:41 AM
BookishBookworm
BookishBookworm - avatar
0
It is same as x = x + 2
27th Feb 2017, 2:09 PM
Priyanshu Sharma
Priyanshu Sharma - avatar