Handouts LectureSlides Lecture5 3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Lets

try it out
def recurMul(a, b):!
if b == 1:!
return a!
else:!
return a +
recurMul(a, b-1)!
!

recurMul

Procedure4
(a, b)
if b == 1:
return a
else:
return a +
recurMul(a, b-1)

Lets try it out


def recurMul(a, b):!
if b == 1:!
return a!
else:!
return a +
recurMul(a, b-1)!
!

recurMul(2, 3)

recurMul

Procedure4
(a, b)
if b == 1:
return a
else:
return a +
recurMul(a, b-1)

Lets try it out


def recurMul(a, b):!
if b == 1:!
return a!
else:!
return a +
recurMul(a, b-1)!
!

recurMul(2, 3)

recurMul

Procedure4
(a, b)
if b == 1:
return a
else:
return a +
recurMul(a, b-1)

Lets try it out


def recurMul(a, b):!
if b == 1:!
return a!
else:!
return a +
recurMul(a, b-1)!

recurMul

Procedure4
(a, b)
if b == 1:
return a
else:
return a +
recurMul(a, b-1)

recurMul(2, 3)

Lets try it out


def recurMul(a, b):!
if b == 1:!
return a!
else:!
return a +
recurMul(a, b-1)!

recurMul

Procedure4
(a, b)
if b == 1:
return a
else:
return a +
recurMul(a, b-1)

recurMul(2, 3)

2
a

Lets try it out


def recurMul(a, b):!
if b == 1:!
return a!
else:!
return a +
recurMul(a, b-1)!

recurMul

Procedure4
(a, b)
if b == 1:
return a
else:
return a +
recurMul(a, b-1)

recurMul(2, 3)

Some observaDons
Each recursive call to a funcDon creates its
own environment, with local scoping of
variables
Bindings for variable in each frame disDnct,
and not changed by recursive call
Flow of control will pass back to earlier frame
once funcDon call returns value

You might also like