def each_fact(n) res = 1 for i in 0 .. n res = res * i unless i == 0 yield(res) end res end res = 0 each_fact(10) do | i | res = res + i end puts res