ruby - Unexpected $end after while loop and nested if -
i have program working on supposed find sum of first 1000 prime numbers. concerned making sure program finding first 1000 prime numbers, add functionality adding them later. here have:
#!/usr/bin/ruby def prime(num) is_prime = true in 2..math.sqrt(num) if (num % i) == 0 is_prime = false else is_prime = true end end return is_prime end = 2 number_of_primes = 0 while number_of_primes < 1000 prime = prime(i) if prime == true number_of_primes++ end i++ end
when try run program following feedback:
sumofprimes.rb:32: syntax error, unexpected keyword_end sumofprimes.rb:34: syntax error, unexpected keyword_end
what gives? direction appreciated.
ruby doesn't have ++
operator, need += 1
number_of_primes += 1
Comments
Post a Comment