468,241 Members | 1,399 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,241 developers. It's quick & easy.

recursion with or without return?

when using recursion should one use a return statement or not?

there is a difference obv since with a return statement it will
ultimately return a value if not recursing forever.

but is there a guideline for this or it just taste or is it
considering good style or pythonic to always have a returnvalue?
Jun 27 '08 #1
1 3550
On Sun, 25 May 2008 00:00:14 -0700, notnorwegian wrote:
when using recursion should one use a return statement or not?
This decision has nothing to do with recursion. It's the same as in
non recursive functions. If the function calculates something that you
want to return to the caller you have to use ``return``. If the function
just has side effects, e.g. printing a tree structure recursively, you
don't have to ``return`` something.
but is there a guideline for this or it just taste or is it
considering good style or pythonic to always have a returnvalue?
Well, you always have a return value anyway because there's an implicit
``return None`` at the end of every function.

Ciao,
Marc 'BlackJack' Rintsch
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Jakle | last post: by
43 posts views Thread by Lorenzo Villari | last post: by
75 posts views Thread by Sathyaish | last post: by
19 posts views Thread by Kay Schluehr | last post: by
13 posts views Thread by Mumia W. | last post: by
15 posts views Thread by Gigs_ | last post: by
30 posts views Thread by Jeff Bigham | last post: by
35 posts views Thread by Muzammil | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.