The other thing that's really recommended,

is don't start by having

students write their own recursive code.

This usually they've told a lot of frustration like,

I just don't even know what to do or type.

Start by giving students programs to modify.

But before we jump into that,

let's look at one simpler program.

Those ones I gave you they looked really cool,

but honestly, they're quite complex.

So let's start with a simpler example.

Here's a piece of code that I will give you that I think

is one of the best things

to start with when teaching kids recursion.

It's got that same nesting doll structure

and it's really obvious,

maybe what that nesting doll structure is,

but let's pull it out for you.

Making that a little bigger,

this is what I'm going to call the nested squares code.

This top, the square on the outside,

that's what we're going to start,

this is going to be the very first thing I'll be drawing.

This is drawing a square of 100 steps on each side.

Inside that, the Russian doll investing part,

is a square that has 10 steps smaller.

So in this case,

a square of 90 on each side and the next one is

80, and so on.

We can draw the arrows in,

but this smallest one I'm telling you,

this is of size 10.

So then you can start thinking it's like "Okay,

where do we stop in factorial?

We went all the way down to one,

in some of the others,

we saw some bases there. What have we got?"

Well, here is the code for my drawing nested square.

So it takes one parameter,

that's the side length,

and if the side length is greater than five,

so that's going to be where I'll stop.

Well, let's walk through it and highlight it for you.

I'm going to use this part here,

if the side length is greater than five,

then I'm going to do what I

call the draw the square portion.

So I'll just tell you that I

start my arrow up in the top there.

So if I passed on 100

like I said I did, that's greater than five.

Basically now, I'm going to repeat four times move

100 steps turning 90 degrees at each end.

After that, this next set of

four instructions is actually going to move my pointer,

changing the exponent by five,

that's going to move it further to

the right and the y-coordinate by negative five,

is going to move it down and that's going to identify

that top-left corner of the 90 square.

So the second square and now this is going to be in

that top left corner and ready to start again.

Then this is what we call the recursive call.

So this is where I'm going to

define how draw nested square works.

By calling drawn nested square again,

saying ''I want you to solve

the same problem but for a smaller size."

So I'm going to subtract

10 off there and that's why you go

from 100 down to 90.

So giving you some vocabulary,

when we talk about recursion,