tags:

views:

108

answers:

3

Looking at this block, I can follow the whole program until I hit, sum += square.

What is he point of this line, what does it say???

sum = 0

[1, 2, 3, 4].each do |value|

square = value * value

sum += square

end

puts sum
+7  A: 
sum = sum + square
vladv
Doh!!! Sorry thanks mate!!
WANNABE
+1  A: 

For Ex

sum=4 
sum += 5  #9
Salil
Thanks very much for this Salil
WANNABE
+1  A: 

Big explination of 'compound operators' here.

http://stackoverflow.com/questions/2493140/meaning-of/2589389#2589389

Glycerine
thanks very much mate
WANNABE
The question is for Ruby, that thread is for C#
Marc-André Lafortune
+= works the same in any language. - I'd like to add I know nothing about c# and I didnt want to copy paste that answer.
Glycerine