Unexpected $end after while loop and nested if

I have this program that I am working on that is supposed to find the sum of the first 1000 prime numbers. Currently all I am concerned with is making sure that the program is finding the first 1000 prime numbers, I will add the functionality for adding them later. Here is what I have:

#!/usr/bin/ruby

def prime(num)

    is_prime = true

    for i in 2..Math.sqrt(num)

        if (num % i) == 0           
            is_prime = false
        else
            is_prime = true
        end
    end

    return is_prime
end


i = 2
number_of_primes = 0

while number_of_primes < 1000

    prime = prime(i)

    if prime == true
        number_of_primes++

    end
    i++
end

When i try to run the program I get the following feedback:

sumOfPrimes.rb:32: syntax error, unexpected keyword_end
sumOfPrimes.rb:34: syntax error, unexpected keyword_end

what gives? Any direction is appreciated.

Answers


Ruby doesn't have ++ operator, you need to do += 1

number_of_primes += 1

Need Your Help

Jump sprite body using ccJumpto

cocos2d-iphone box2d-iphone

I have issue in jumping sprite body. Following is the update method for jumping sprite body

adding different tableviews on a scrollview controlled by a page control

ios objective-c uitableview uiscrollview uipagecontrol

I have added different tableviews on a scrollview that are controlled by a page control. I am setting them like this.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.