Pit Capitain wrote:

>   (2...50).reject{|n|(2..Math.sqrt(n)).find{|x|n % x == 0}}
>
> It's not what the OP wanted, though.

include Math
primes = (2...10).map{|n|(2..sqrt(n)).find{|x|n % x == 0}}
primes.each_with_index do |x,n|
  n += 2
  if x then puts "#{n} equals #{x} * #{n/x}"
  else puts "#{n} is a prime number" end
end
__END__

It is now.

Or, for readability's sake:

include Math
primes = (2...10).map{|n|[n,(2..sqrt(n)).find{|x|n % x == 0}]}
primes.each do |n,x|
  if x then puts "#{n} equals #{x} * #{n/x}"
  else puts "#{n} is a prime number" end
end
__END__

So, no, there may not be an exact equivalent to for/else, but as with 
interface definitions in Python/Ruby, you generally find that the need 
isn't there like it is in the other language. In Java, types are 
staticly declared, and mixins are nonexistent, making interfaces very 
important. In Python, there's a difference between statements and 
expressions (IIUC), making special iterator constructs like for/else 
important. IOW, it shouldn't be considered a fault of Ruby's that it 
doesn't include that construct -- it doesn't need it.

Devin