aris
September 30, 2012, 5:49pm
1
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
roelof
September 30, 2012, 5:53pm
2
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.
roelof
September 30, 2012, 5:54pm
3
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
roelof
September 30, 2012, 6:56pm
4
Thanks it worked now and I solved the problem. Roelof
Date: Mon, 1 Oct 2012 00:54:05 +0900