-
One thing you'll hear or see referred to a lot
-
is something called a flowchart
-
either in computer science, so really when people
-
talk about any type of algorithm or process.
-
So what I thought I would do
-
is for every program I write, is do a simple flowchart
-
maybe I won't do it for every one,
-
but I'll start with one of the basic ones,
-
just so we understand that a flowchart isn't anything fancy.
-
So in this factorial program that we had been looking at in the past couple videos,
-
any flowchart you're just going to be at a starting point
-
I guess, depicted with a circle or oval of some kind.
-
And so we start at this line above this assignment
-
of the number where we actually ask for input from the user.
-
And then after that, we ask for input from
-
the user. This line right here.
-
We are asking for input from the user.
-
So this right over here
-
And we will depict that by a parallelogram.
-
And that is input from the user.
-
And then we'll just say number
-
equals user input.
-
And you can be a little bit loosey-goosey with the terminology
-
here, you're really just trying to tell us what you're doing in this step.
-
The parallellogram tells us that we are somehow interfacing with the user.
-
We're either taking something from the user or we're outputting something to the user.
-
So here, we're saying user input is equal to number.
-
We're assigning number to user input.
-
Then, the next thing we do is just a straight up operation.
-
We just set product to be equal to 1
-
And there we just do that in a rectangle.
-
Product equals 1.
-
Product is equal to one.
-
And then, something interesting is going to happen.
-
We enter into our for loop.
-
And we start with, and what I'm going to do here
-
is I'm going to write it a little bit different than we wrote it over here.
-
So we do is we start a
-
What we are doing is
-
We are going to start our for-loop
-
essential with an assignment
-
Where we assign
-
For loop is really a bunch of things
-
Happening at the same time
-
It assigns "i" to the first number in the sequence
-
or it tests whether it can assign "i" to the first number in the sequence
-
if it can
-
then it proceeds
-
if it can't
-
then it breaks out of the for-loop
-
so let me put it this way
-
i will do kind off a test case
-
right over here
-
So items left in sequece
-
so item left
-
in sequence
-
and when I'm referring to the sequence I'm talking about
-
this sequence over here
-
the range of our number
-
in the example i gave in the last video
-
the number was "3"
-
so items left in this sequence
-
i know it's hard to read
-
right over here
-
If there are, so lets say that there are
-
items left in the sequence
-
so if there are items left in the sequence
-
so we'll just say
-
"i" is equal to next item
-
"i" is equal to next
-
"i" is euqal to the next item
-
if there are
-
well i'll just hold off for the case
-
where there are no items left in the sequence
-
but lets say that there are
-
"i" is equal to the next item
-
and then we also define
-
we define "product"
-
to be
-
we define "product"
-
actually i wanted to do these in blue
-
just our regual
-
or regular
-
se let me write this
-
is "YES"
-
if there are items in the sequence
-
then "i" is equal to the next item
-
is equal to the next item
-
thats one operation we do
-
and then we reset "product"
-
we reassign "product" to be equal to
-
what the former value of the "product" was
-
times "i" plus 1
-
and at this point
-
we essentially loop back
-
to this test over here
-
so at this point
-
we loop back
-
i'll try to write it neatly
-
we loop back to
-
we loop back to this point in the program
-
that's why it is called a loop!
-
cause after you preform this operation
-
this is in bedded in the loop
-
you go back to the beginning
-
to see if there is any more of the loop to do
-
so you go
-
back to the beginning before the loop and say
-
"hey, are there any items in the sequence"
-
and this should be a question mark over here
-
these kind of question mark decision points
-
are usually specified with this diamond
-
if there is another item in the sequence
-
then "i" is equal to the next item and "product" is
-
equal to what "product" was times "i" plus one
-
we go to the next
-
"are there items left in the sequence?"
-
and at some point there won't be any items
-
left in the sequence
-
so there won't be, at some point there won't be
-
items left in the sequence
-
and we can go to the right or i'll just break out of it down here
-
and now we have broken out of this for-loop
-
we have boken out of this for-loop
-
and then the next thing we do
-
once we are done with our for-loop
-
is we just print the value of "product"
-
we just output the value of "product"
-
so that is an interaction with the user
-
so we are literally just outputting the value of "product"
-
so we output
-
output "product"
-
and we are done!
-
and i can write end
-
for the end of our program
-
and the program will stop running
-
end
-
so this is just a simple flowchart for this simple program
-
and hopefully it helps you appreciate
-
that one little understanding of the program
-
itself if the last two videos didn't help too much
-
and also gives you a simple understanding
-
of how to write a flowchart