From: Jim Freeze Date: 2002-12-17T08:52:44+09:00 Subject: How to return value from middle of a block? Hi: I am trying to return a value from a middle of a block, but when I do, it exits the block. Here is the code: def _parse loop { puts yield } end def parse i = 0 _parse { # This code returns nil, but keeps going. # prints # 1 # 2 # nil # ... #i+=1 == 3 ? rtn = nil : rtn = i #rtn # This code quits when it see return # prints # 1 # 2 i += 1 if i == 3 return nil end i } end parse Is there a syntax for returning a value from the middle of a block? I know that I can always set a return value and let execution drop to the bottom of the block, but it is discomforting for there to be a difference betweeen an implicit return and an explicit return. -- Jim Freeze ---------- Hofstadter's Law: It always takes longer than you expect, even when you take Hofstadter's Law into account.