From: Lloyd Zusman Date: 2007-02-20T00:47:07+09:00 Subject: Re: return statement Derek Teixeira writes: >> def square(n) >> s = n*n >> return s >> end >> > so right here we could have gotten rid of the "return" and then below > just write > > puts square(3) > > and the code will give us 9? > because it returns to us that s value, and we are putting that value? You can do the "puts square(3)" and "9" will print out whether the "return" statement is there or not, because in every function, if there is no "return", the final value calculated before the "end" is implicitly passed to the caller as if the "return" were present. In your "square" function, the final value calculated is the value of "s = n*n", and therefore, that would be the value that is implicitly passed to the caller if the "return" were missing. For example ... def square1(n) # no return statement s = n*n a = 12345 # this gets implicitly returned end def square2(n) # with a return statement s = n*n a = 12345 return s # explicitly returns s end puts square1(3) => 12345 puts square2(3) => 9 -- Lloyd Zusman ljz@asfast.com God bless you.