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.
Ruby doesn't have ++ operator, you need to do += 1
number_of_primes += 1