Prime numbers problem

Hello,

I found out that ruby 1.9 has a prime class.
So I tried this : list_primes.each { |prime| print prime, " "; break
unless prime < 90 }

And I get this answer : 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59
61 67 71 73 79 83 89 97

That looks no good because 97 is more then 90.

How can this be happen ?

Roelof

On Sun, Sep 30, 2012 at 5:48 PM, Roelof W. [email protected]
wrote:

Hello,

How can this be happen ?

Because the loop first print, and checks later.

On Monday 01 October 2012 Roelof W. wrote

How can this be happen ?

Roelof

Well, you’re telling ruby to break the loop after having printed out the
number, so of course it’ll print 97, then break the loop. You’ll need to
reverse the order of the expressions inside the block to achieve what
you
want.

Stefano

Thanks it worked now and I solved the problem. Roelof

Date: Mon, 1 Oct 2012 00:54:05 +0900