[Tutor] [Fwd: Re: What is this kind of loop called]

Luke Paireepinart rabidpoobear at gmail.com
Mon Jun 8 06:48:43 CEST 2009


>>>
>>> def get(numbers):
>>>     print 'Calling ', numbers
>>>     sleep(1)
>>>     print 'Connected '
>>>     sleep(1)
>>>
>>> def call_numbers():
>>>     for i in range(9549355543, 9549355560):
>>>         numbers = i
>>>         get(numbers)
>>> call_numbers()
>>>
>>> Is there a technical name for a loop like this?
>>
>> For loop? That is what I call it.
>>
>>
> As usual I am not very clear, see how the call_numbers() for loop gets 
> passes to the get(numbers) to do something else, that is what I was 
> asking about.
>
That part is not considered a loop.

There is a type of programming paradigm called "recursion" that is 
similar to loops, perhaps that's what you're thinking of?

def recursive_sum(num):
    if num == 0:
        return 0
    else:
        return num + recursive(num - 1)

 >>> recursive_sum(15)
120
 >>> sum(range(16))
120

However your example is not recursion, because the function does not 
call itself repeatedly; rather, call_numbers is called once, and then it 
repeatedly calls a _different_ function.  Savvy the difference?
HTH,
-Luke



__________ Information from ESET NOD32 Antivirus, version of virus signature database 4136 (20090606) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




More information about the Tutor mailing list