From: hal9000@... Date: 2000-10-19T07:40:02+09:00 Subject: [ruby-talk:5679] Re: local variables (nested, in-block, parameters, etc.) See below... In article <39EDE85F.C6FBB86C@earthlink.net>, Charles Hixson wrote: > "Hal E. Fulton" wrote: [snip] > I expected the loop variable to evaporate, and > instead it staked permanent residence in whatever the current scope was, and I > presume that it would do the same in a real program rather than just in an > eval.rb test. Definitely something to watch out for! Well, I see it as a feature rather than a bug... the only problem I see if when (as I showed before) a for-variable is named the same as an existing local variable and thus clobbers it. This is related to our original topic, in a way, isn't it? Actually, this feature couldn't bite me, because I habitually would never name a for-variable the same as an existing variable. And the reason I consider it a feature is that if I break out of the loop, I can retrieve the value without having to save it off first. You may also find this interesting: If a for-variable is modified during the loop, that value remains in effect for the rest of the loop, but has no effect on subsequent execution. The for-loop simply assigns values in sequence, blindly and happily (as I think it should). for i in 1..10 print i, "\n" if i == 3 i = 7 end end The loop above will execute exactly ten times. Hal -- Hal Fulton Sent via Deja.com http://www.deja.com/ Before you buy.