consider the function
if we write this infinite recursive function then it gives the error:
with the final line repeating over and over.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in infinite_recursion
if we just have an infinitely repeating loop. ie:
we never get an error, and it just keeps repeating the loop, doing as its told.
recursive function to generate
for fibonacci sequence:
if n <= 1: return 1 #base case
return n+n_sum(n-1) #inductive step
for fib(0) and fib(1) we call our function once only (as it is covered in the base case)
if n <= 1: return 1 #covers our base cases
return nth_fib(n-1) + nth_fib(n-2) #inductive step
for fib(n) we call our function how many times it calls for both and
this is the fibonacci relation, and we have the same initial cases:
ie the function is called 8 times with fib(5).
i = 0
while i < 100:
if i%3 == 2:
print i, "mod", 3, "= 2"
for i in range(0,100):
if i%2 == 0:
print i, "is even"
print i, "is odd"
it will execute zero times.
this is because it executes once for each value i takes in the list . this is an empty list so i takes no values.