CyberSlug Rules!

Beginner Programming CMPS060

Prof. Paulo Franca

Home

Syllabus

Login

Objects

Download

Staff only

How far to the wall? recursion example

Traditional algorithm:

this is how you compute_distance:
howmany=0;
while you see no wall
step ahead;
howmany=howmany+1;
result is howmany

Recursive algorithm:

this is how you compute_distance:
if you see the wall
result is zero;
else
step ahead;
result is 1+compute_distance;
 

Program - any better?