Ruby 中非常非常基本的块:
list = (1..125).to_a
list.each do |x|
print x if 125 % x = 0
end
给我:
ZeroDivisionError: divided by 0
from (irb):3:in `%'
from (irb):3
from (irb):2:in `each'
from (irb):2
然而,“puts x”块返回 1 到 125,就像它应该的那样。
到底是怎么回事?
Ruby 中非常非常基本的块:
list = (1..125).to_a
list.each do |x|
print x if 125 % x = 0
end
给我:
ZeroDivisionError: divided by 0
from (irb):3:in `%'
from (irb):3
from (irb):2:in `each'
from (irb):2
然而,“puts x”块返回 1 到 125,就像它应该的那样。
到底是怎么回事?