From: "Eric D." Date: 2013-06-25T08:33:01+09:00 Subject: Sum method through while loops or iteration I am trying to create a sum method for an empty array, that will return "0" if there is nothing in it and the sum of the values if there are values called through it. I have seen other ways on the internet, but I am relatively new to this, and am under the impression that this can be done with while loops or .each iteration. Below are various things I tried, some were actual thoughts some were out of sheer frustration. Thanks for your help! 1. def sum (array) array = [] while array >0 array.each { |a| sum+=a } end 2. def sum x= [] x.each{|element| element +element } end 3. def sum(array) while array.length > 0 puts "#{array[x+y+z]}" else puts "0" -- Posted via http://www.ruby-forum.com/.