From: brabuhr@... Date: 2009-07-26T08:48:29+09:00 Subject: Re: Please debug this program On Sat, Jul 25, 2009 at 7:24 PM, Brian Candler wrote: > I'm surprised it even ran at all: > > def factorial(x) >  if (x==0) then >    return (1) >    end >    else >      ... something else > > This doesn't make sense syntactically - an 'else' without an 'if'. An 'else' can live inside a method or a begin...end: > ruby y y:6: warning: else without rescue is useless FOO ELSE FOO y:3:in `foo': FOO (RuntimeError) from y:9 > cat y def foo(n) puts "FOO" raise "FOO" if n rescue puts "RESCUE" else puts "ELSE" end foo(false) foo(true) > ruby y FOO ELSE FOO RESCUE http://rubycentral.com/pickaxe/tut_exceptions.html "The else clause is a similar, although less useful, construct. If present, it goes after the rescue clauses and before any ensure. The body of an else clause is executed only if no exceptions are raised by the main body of code."