On Tue, Mar 22, 2011 at 11:15 AM, Sebastian Gr=E4=DFl
<sebastian / validcode.me> wrote:
> it is just syntatical sugar. Both are essentially equal.
> The only difference is that each is a method of an Enumerable.

That's not true.  There is also a scoping difference:

11:43:58 ~$ ruby <<CODE
a=3D%w{foo bar}
for e in a
p e
end
p e
a.each do |x|
p x
end
p x
CODE

"foo"
"bar"
"bar"
"foo"
"bar"
-:9: undefined local variable or method `x' for main:Object (NameError)
11:44:19 ~$

A block opens a new scope wile for doesn't.

I believe there is also a slight runtime difference but that really
only matters if you need to squeeze the last bit of performance out of
your application.

Kind regards

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/