Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
the difference between for-loop and each
Andreas S
10/19/2007 7:21:00 PM
Hopefully (I'm sure) somebody can shed a light on this. This caught me by surprise
ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-linux]
test.rb:
TEST = []
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
>> ruby test.rb
#
3
#
3
#
3
With each
>> ruby test.rb
#
1
#
2
#
3
I thought for-loop behaves the same as each. Apparently not. Why is this and is this a good thing?
Thank you in advance
-andre
_________________________________________________________________
Windows Live Hotmail and Microsoft Office Outlook – together at last. Get it now.
http://office.microsoft.com/en-us/outlook/HA102225181033.aspx?pid=CL10...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
the difference between for-loop and each
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password