The Rubyist's Loop

$VERBOSE = nil    # We'll explain this at the end of the lesson.
require 'prime'   # This is a module. We'll cover these soon!

def first_n_primes(n)

return "n must be an integer." unless n.is_a? Integer
return "n must be greater than 0." if n <= 0
  prime_array ||= [] 
  prime =
  n.times { prime_array.push( }


What’s wrong whit this? Every time I hit “RUN” it start thinking and it keeps there…


Please post a link to the exercise. Thanks.


Finally worked

  prime =
  n.times do prime_array.push(



That was going to be my first suggestion.


Yeah, tyvm, but that one was a changed version of the actual code that I did.
Tried many ways even without caps untill I got the “DO” in there.


A block expression will work…

n.times {prime_array.push(}


It didn’t :P!
Had to go with “DO”


Weird, the block expression worked for me. You should be done that unit by now. Quite a difference at the end, eh?


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.