Ruby意外关键字结束,AND意外结束输入

时间:2013-09-12 14:01:38

标签: ruby

我的代码如下。如果我删除了最后一个end,则会显示unexpected end of input,如果我重新插入end,则会显示unexpected keyword end。我看不出以下代码有什么问题。你能吗?

n = gets.chomp.to_i
array= Array.new(n, true)
while p<Math::sqrt(n) do
  i=p
  while (i<=n) do
    array[i] = false # not a prime
    i+=p
  end
  while array[p]!=true do
    p++
  end
end

1 个答案:

答案 0 :(得分:18)

增量运算符(++):

p++
Ruby中不存在

。你的意思是:

p += 1
相关问题