From: matt@... (matt neuburg) Date: 2009-03-12T01:23:02+09:00 Subject: Re: return doesn't always exit my method Benjamin Thomas wrote: > If I type 'exit', the function should normally exit, via a return > statement. But this does not always happen and I really can't understand > why. I've been scratching my head for a few hours on that so I'm posting > here hoping somebody will be able to spot my obvious mistake! > > I'm trying to apply here the concept of recursion so maybe this is where > I'm messing up. To abort a deep call chain, you can use catch() and throw(): def go_deeper(level) throw(:done) if level > 3 puts "Level #{level}" go_deeper(level+1) end catch(:done) {go_deeper(0)} puts "finished" m. -- matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/ Leopard - http://www.takecontrolbooks.com/leopard-customizing.html AppleScript - http://www.amazon.com/gp/product/0596102119 Read TidBITS! It's free and smart. http://www.tidbits.com