Let us briefly take a look at an example algorithm,

and how you might follow its steps yourself.

We don't need to know anything about programming to do these steps,

we just need to be able to do some math,

and keep careful track of what we're doing.

This algorithm does not accomplish a really useful task,

but gives us a simple example to start from.

The algorithm says, "Given a non-negative integer N," so it is

parameterized over N. We need a value of N to actually do these steps,

so let's pick N equals two.

We're also going to want a place to write down the output that the algorithm produces,

that is, everything that we are told to write down,

we will write in this output box.

We need to keep track of where we are,

so we are going to use this green arrow to remember what step we are currently on.

We'll start at the start.

The step right after the arrow says to make a variable called X,

and set it equaled to N plus two.

N is two, and two plus two is four,

so we want to note that X is initially four.

Our next step calls for us to count from zero to

N. We will want to give a name to the number we are counting,

so that we can use it in our other steps.

Here, we decided to call it i.

As we count, we are going to repeat steps.

We've used indentation here to indicate

which steps are repeated for each number we count,

as well as explicitly noting in the step after that you do it,

when you finish counting.

We'll start with i being zero,

since that is the first number we said to count.

Our next step says to write down X times i.

Four times zero is zero,

so we write down zero.

Our next step says for us to update the value of X.

What is its new value?

Four plus zero times two is four,

so, we would update it to be four.

It's already four, which is fine,

we just keep its value as four.

Now, we have reached the end of the steps that we said to do as we count.

We need to go back and count the next number,

so we move our arrow back to the top of the step we were doing for each number,

and make i the next number we would count,

in this case, one.

Now, we begin doing these steps again with i having the value one.

What is X times i now?

Four times one is four,

so we write down the number four in our output.

Next, we are going to update X again, this time,

X plus i times N evaluates to six,

so we are going to change the value of X from four to six.

We've again reached the end of our repeated steps,

so we need to count our next number.

We'd go back to the top,

and then count our next value which is two,

and make that the value of i.

We said to count from zero to N,

and N is two, so are we done counting?

In these steps, we said to include both ends,

so we're going to do these steps when i has the value two.

So, we go in and do the repeated steps one more time.

Now, X times i has the value 12,

so we write down 12 in our output and we go to the next step.

Our next step says to update the value of X again,

evaluating X plus i times N,

we get 10 this time,

so we update the value of X to be 10,

and move past that step.

Once more, we've reached the end of the steps we want to repeat as we count,

so we return to the step where we said to count.

When we return here,

we look at our steps and realize that we've already

counted all of the numbers we were supposed to,

zero, one and two.

So, we're done counting.

Now, we want to go to the steps after we finish counting and do them.

This one says to write down the value of X. X currently has value 10,

so we write that in our output.

Now, our arrow is at the end of our steps.

There's nothing left to do, so we're done.

Zero, four, 12, 10 is the sequence of numbers that this algorithm wanted us to generate,

for N equals two which we see in our output box.