473,320 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 4267
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Jakle | last post by:
Hi all. Need alittle help here. This is an example from "How to Think Like a Computer Scientist: Learning with Python, Chapter 5". It's an open source ebook, so if you feel like it you can find it...
43
by: Lorenzo Villari | last post by:
I've tried to transform this into a not recursive version but without luck... #include <stdio.h> void countdown(int p) { int x;
75
by: Sathyaish | last post by:
Can every problem that has an iterative solution also be expressed in terms of a recursive solution? I tried one example, and am in the process of trying out more examples, increasing their...
19
by: Kay Schluehr | last post by:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496691
2
by: mdeni | last post by:
I am sorry if this was allready asked or discussed, please redirect me. I have to make the program of postorder traversal of the binary search tree NOT using recursion. I have found many solutinos...
13
by: Mumia W. | last post by:
Hello all. I have a C++ program that can count the YOYOs that are in a grid of Y's and O's. For example, this Y O Y O O Y O Y O Y O O Y O Y Y O Y O Y O O Y O O Y Y O Y O
15
by: Gigs_ | last post by:
Can someone explain me this if l == : return else: return f(l) + l # <= cant figure this, how is all sum at the end? thanks!
17
by: AceKnocks | last post by:
I have been given this interface, interface BinarySearchTree { public void insert(Integer data); public int size(); public int height(); public boolean contains(Integer target); }
30
by: Jeff Bigham | last post by:
So, it appears that Javascript has a recursion limit of about 1000 levels on FF, maybe less/more on other browsers. Should such deep recursion then generally be avoided in Javascript?...
35
by: Muzammil | last post by:
int harmonic(int n) { if (n=1) { return 1; } else { return harmonic(n-1)+1/n; } } can any help me ??
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.