+ 1

While loop

What is 'total += number'?

16th Mar 2019, 3:06 PM
Santosh Pattnaik
Santosh Pattnaik - avatar
3 odpowiedzi
+ 14
i = i + 1; OR i += 1; Suppose you had an int variable, sum, and you wanted to add 10 to it. How would you do this? Here's one solution: sum = sum + 10; This kind of operation is very common (where 10 is replaced by whatever value you want). //OR You can use the compound addition assignment operator, which looks like: += (plus sign, followed by equal sign). sum += 10; // Add 10 to sum Suppose, instead of adding a value to sum, you wanted to double it? That is, you wanted to multiply it by 2? One way to do this is : sum = sum * 2; // Multiply sum by 2 //OR sum *= 2; // Multiply sum by 2
16th Mar 2019, 3:25 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 2
I think its correct
16th Mar 2019, 7:43 PM
Sally(Codder)
Sally(Codder) - avatar