I noticed that the use of block/yield differs slightly when a "break" is
called in the code. For example:
class Array
def myI()
self.each{ |aa| yield(aa) }
end
end
[0,1,2].myI { |xx| [10,20,30].myI { |yy| break if(yy==20 and xx==0); puts
"#{xx}:#{yy}" }}'
RESULT:
0:10
1:10
1:20
1:30
2:10
2:20
2:30
==============================================
class Array
def myI(&blk)
self.each{ |aa| blk.call(aa) }
end
end
[0,1,2].myI { |xx| [10,20,30].myI { |yy| break if(yy==20 and xx==0); puts
"#{xx}:#{yy}" }}'
RESULT:
0:10
0:30 # This result was not expected
1:10
1:20
1:30
2:10
2:20
2:30
My question is, why, when using the second method, does the "break" not seem
to break completely out of the loop, but rather acts like a "next" by
terminating the current unit of iteration. I would not expect to get the
"0:30" result. I was under the impression that block.call/yeild were
synonymous.
_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail