Ruby [已经解决] Ruby 编程语言 第 133-134 页 有一个疑问

shin · December 10, 2012 · Last by small_fish__ replied at December 10, 2012 · 1936 hits
def sequence(n, m, c)
  i = 0
  while(i<0)
    yield m * i + c
    i += 1
  end
end
sequence(3,5,1) {|y| puts y}

结果是 1 6 11

如果我把方法中 yield 删除,程序也运行顺利,求解?

def sequence(n, m, c)
  i = 0
  while(i<0)
    m * i + c
    i += 1
  end
end
sequence(3,5,1) {|y| puts y}

结果是 1 6 11

你确定你把 yield 删除还能打印出来?

你的 while 循环写的貌似就不对吧

@ptmagic 失误,删除后打印不出了!

貌似是 while(i<n)吧

You need to Sign in before reply, if you don't have an account, please Sign up first.