# [Edu-sig] understanding recursion

John Posner jjposner at snet.net
Fri Feb 9 21:22:53 CET 2007

```Andy Judkis <ajudkis at verizon.net> wrote:

> ... I've found that many kids seem to have a natural ability
> to use recursion, but they don't realize that they're doing it, and
> they don't understand the implications.
>
>   ...
>
> def play_game():
>     . . .
>     resp = raw_input("Play again?")
>     if resp == "yes":
>         play_game()
>

My guess, Andy, is that many of the students are not thinking clearly enough
to understand the difference between REPETITION and RECURSION. They haven't
thoroughly learned the flow-of-control aspect of functions/subroutines.
That's not surprising: in real life, kids don't have to formally declare one
activity to be finished before they "go to" (heh heh) another activity.

IMHO, the kids' first attempt at coding provides an excellent opportunity
for you to gently move them from the realm of almost-right "fuzzy" thinking
to "crisp" formal algorithmic thinking.

> ...  My expectation was that they'd write a loop like this:
>
> while True:
>     play_game()
>     resp = raw_input("Play again?")
>     if resp == "no":
>         break
>

Another guess: not many kids will hit upon the "while True ... break" coding
scheme on their own. I'd be inclined to let them use this imperfect solution
at first:

for i in range(1000000):
play_game()
...

Then you can point out the limitations, inefficiencies, lack of elegance of
this solution -- e.g. to quit the game, you have to type Ctrl-C or close the
window.

Best,
John

```