Handouts LectureSlides Lecture5 3
Handouts LectureSlides Lecture5 3
Handouts LectureSlides Lecture5 3
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)
recurMul
Procedure4
(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)
recurMul
Procedure4
(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)
recurMul(2, 3)
2
a
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