From: Charles Hixson Date: 2000-10-18T04:10:02+09:00 Subject: [ruby-talk:5648] Re: local variables (nested, in-block, parameters, etc.) This is a multi-part message in MIME format. --------------1AFE1D8965C8E3C8016D7065 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Yukihiro Matsumoto wrote: > Hi, > > ... example 1: > i = nil > [1,2,3].each{|i| break if condition(i)} > p i > > Of course, rewriting it to > example 2: > x = nil > [1,2,3].each{|i| if condition(i) > x = i > break > end > } > p x > > is easy, but tiresome. Yes, I'm lazy. > > matz. I find the first form the be more intelligible with less effort than the second form. I am an extreme newbie to Ruby, though experienced in several other languages. I would prefer that the code in example 1, if in a real program, use a different local variable, but I did understand with little effort that it was intended to be a local variable. Any other choice would have increased my surprise. Several languages that use an approximately equivalent form also require that tie loop control variable be local. I think that the languages that don't make this choice are in the minority. And deservedly so. -- (c) Charles Hixson -- Addition of advertisements or hyperlinks to products specifically prohibited --------------1AFE1D8965C8E3C8016D7065 Content-Type: text/x-vcard; charset=us-ascii; name="charleshixsn.vcf" Content-Transfer-Encoding: 7bit Content-Description: Card for Charles Hixson Content-Disposition: attachment; filename="charleshixsn.vcf" begin:vcard n:Hixson;Charles x-mozilla-html:FALSE adr:;;;;;; version:2.1 email;internet:charleshixson@earthling.net fn:Charles Hixson end:vcard --------------1AFE1D8965C8E3C8016D7065--