From: Austin Ziegler Date: 2002-07-09T23:43:36+09:00 Subject: Re: for ... else ... end On Tue, 9 Jul 2002 23:19:05 +0900, Kontra, Gergely wrote: > For the keyword war: (silly, dummy example) > > cnt=0 > for i in anArray do > break if i<0 > res=19*i+4-i > puts res > cnt+=res > else > puts "Empty array" > on_exit > puts "The result is #{cnt}" > on_break # or on_abort > # ok, I admit it is like an exception... > puts "Invalid negative element found in the array!" > end > > So, in any kind of loop: > > else : code block is not executed > on_exit : code block is executed, and terminated normally > on_break / on_abort : code block executed and exited via 'break' > > These modifiers are in connection with the whole loop, not one > iteration, so perhaps another arrangement will be better. I like your naming, but will it work as well for: cnt=0 anArray.each do |i| break if i<0 res=19*i+4-i puts res cnt+=res else puts "Empty array" on_exit puts "The result is #{cnt}" on_break # or on_abort # ok, I admit it is like an exception... puts "Invalid negative element found in the array!" end More than that, what will happen if else/on_exit/on_break is done in a non-looped block? As far as I can tell, blocks don't have any context as to whether they are run in a loop or not. If I'm implementing my own mytype#each, how do I make this work? How do I yield to the blocks that else/on_exit/on_break represent? -austin -- Austin Ziegler, austin@halostatue.ca on 2002.07.09 at 10.38.39