Omit Needless Words - infinite loop


So, this code actually is correct, as far as the course realizes - if I comment out or remove the function call, it accepts the code and allows me to progress.


If I call the function, with ANY input, it gets stuck in an infinite loop. Anybody have any ideas why? None of the other threads I've been able to find seem to have anything useful to change apart from the 'return/puts' kind of change, which also does nothing.

$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.isa_a? Integer
    return "n must be greater than 0." if n <= 0
  prime_array ||= []
  prime =
  for num in (1..n)
  return prime_array



There are a couple of things I spotted in your code that should fix this for you:

  1. isa_a? should be is_a?
  2. fire_n_primes(2) should be first_n_primes(2)


Haha, typos! Thanks for catching those. That said, there is zero change in the code's response after correcting those - it still infinite loops when I try to run it.

And, amusingly, the typos didn't stop it from allowing me to continue. I'm really baffled by this particular page, and I want to figure it out before I move on so I don't make more looping mistakes.

I've infinite looped myself FAR too many times as it is.


Another thing you can do is to change

$VERBOSE = nil


$VERBOSE = true

I think one of the problems here is that when $VERBOSE = nil, it suppresses useful error messages, so changing this flag might give you more information about what's going wrong.


Well, that's producing some interesting responses. Amusingly, when I came back to look at it again this morning, the code for that lesson seems to work fine now - but following lessons are producing their own interesting errors. The 'Less Is More' step won't function without the RETURN statement...that they force you to remove, preventing progress, yet somehow I have that step completed.

And now the Rubyist's Loop is displaying this error: Prime::new is obsolete. use Prime::instance or class methods of Prime.
Which implies to me that there's something wrong with the Codecademy portion of this parser, not the lesson or lesson's code itself.


It seems like you tried to use ruby like java TBH


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