一千萬個為什麽

搜索

Ruby中的+ =是什麽意思?

Possible Duplicate:
What does “+=” (plus equals) mean?

下面的 sum + = square 有什麽意義?這是什麽意思?

sum = 0
[1, 2, 3, 4].each do |value|
  square = value * value
  sum += square
end
puts sum

最佳答案

sum = sum + square

轉載註明原文: Ruby中的+ =是什麽意思?