473,287 Members | 1,709 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,287 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 4266
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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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)...

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.