the difference between for-loop and each

A

Andreas S

Hopefully (I'm sure) somebody can shed a light on this. This caught me by s=
urprise

ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-linux]
test.rb:
TEST =3D []
def procs &block
TEST << block
end

#for n in [1,2,3] do
[1,2,3].each do |n|
procs do
puts "#{n}"
end
end

TEST.each do |t|
puts t
t.call
end

With for loop#
3
#
3
#
3

With each#
1
#
2
#
3

I thought for-loop behaves the same as each. Apparently not. Why is this an=
d is this a good thing?

Thank you in advance
-andre
_________________________________________________________________
Windows Live Hotmail and Microsoft Office Outlook =96 together at last. =A0=
Get it now.
http://office.microsoft.com/en-us/outlook/HA102225181033.aspx?pid=3DCL10062=
6971033=
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top