Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby unexpected keyword end, AND unexpected end of input

Tags:

ruby

My code is as follows. If I remove the last end, it says unexpected end of input, if I put the end back in, it says unexpected keyword end. I cannot see anything wrong with the following code. Can you?

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
like image 553
Aydin Avatar asked Sep 12 '13 14:09

Aydin


1 Answers

The increment operator (++):

p++

does not exists in Ruby. You meant:

p += 1
like image 98
Shoe Avatar answered Nov 15 '22 16:11

Shoe