-
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.
-
Not Synced
So we do is we start a
-
Not Synced
What we are doing is
-
Not Synced
We are going to start our for-loop
-
Not Synced
essential with an assignment
-
Not Synced
Where we assign
-
Not Synced
For loop is really a bunch of things
-
Not Synced
Happening at the same time
-
Not Synced
It assigns "i" to the first number in the sequence
-
Not Synced
or it tests whether it can assign "i" to the first number in the sequence
-
Not Synced
if it can
-
Not Synced
then it proceeds
-
Not Synced
if it can't
-
Not Synced
then it breaks out of the for-loop
-
Not Synced
so let me put it this way
-
Not Synced
i will do kind off a test case
-
Not Synced
right over here
-
Not Synced
So items left in sequece
-
Not Synced
so item left
-
Not Synced
in sequence
-
Not Synced
and when I'm referring to the sequence I'm talking about
-
Not Synced
this sequence over here
-
Not Synced
the range of our number
-
Not Synced
in the example i gave in the last video
-
Not Synced
the number was "3"
-
Not Synced
so items left in this sequence
-
Not Synced
i know it's hard to read
-
Not Synced
right over here
-
Not Synced
If there are, so lets say that there are
-
Not Synced
items left in the sequence
-
Not Synced
so if there are items left in the sequence
-
Not Synced
so we'll just say
-
Not Synced
"i" is equal to next item
-
Not Synced
"i" is equal to next
-
Not Synced
"i" is euqal to the next item
-
Not Synced
if there are
-
Not Synced
well i'll just hold off for the case
-
Not Synced
where there are no items left in the sequence
-
Not Synced
but lets say that there are
-
Not Synced
"i" is equal to the next item
-
Not Synced
and then we also define
-
Not Synced
we define "product"
-
Not Synced
to be
-
Not Synced
we define "product"
-
Not Synced
actually i wanted to do these in blue
-
Not Synced
just our regual
-
Not Synced
or regular
-
Not Synced
se let me write this
-
Not Synced
is "YES"
-
Not Synced
if there are items in the sequence
-
Not Synced
then "i" is equal to the next item
-
Not Synced
is equal to the next item
-
Not Synced
thats one operation we do
-
Not Synced
and then we reset "product"
-
Not Synced
we reassign "product" to be equal to
-
Not Synced
what the former value of the "product" was
-
Not Synced
times "i" plus 1
-
Not Synced
and at this point
-
Not Synced
we essentially loop back
-
Not Synced
to this test over here
-
Not Synced
so at this point
-
Not Synced
we loop back
-
Not Synced
i'll try to write it neatly
-
Not Synced
we loop back to
-
Not Synced
we loop back to this point in the program
-
Not Synced
that's why it is called a loop!
-
Not Synced
cause after you preform this operation
-
Not Synced
this is in bedded in the loop
-
Not Synced
you go back to the beginning
-
Not Synced
to see if there is any more of the loop to do
-
Not Synced
so you go
-
Not Synced
back to the beginning before the loop and say
-
Not Synced
"hey, are there any items in the sequence"
-
Not Synced
and this should be a question mark over here
-
Not Synced
these kind of question mark decision points
-
Not Synced
are usually specified with this diamond
-
Not Synced
if there is another item in the sequence
-
Not Synced
then "i" is equal to the next item and "product" is
-
Not Synced
equal to what "product" was times "i" plus one
-
Not Synced
we go to the next
-
Not Synced
"are there items left in the sequence?"
-
Not Synced
and at some point there won't be any items
-
Not Synced
left in the sequence
-
Not Synced
so there won't be, at some point there won't be
-
Not Synced
items left in the sequence
-
Not Synced
and we can go to the right or i'll just break out of it down here
-
Not Synced
and now we have broken out of this for-loop
-
Not Synced
we have boken out of this for-loop
-
Not Synced
and then the next thing we do
-
Not Synced
once we are done with our for-loop
-
Not Synced
is we just print the value of "product"
-
Not Synced
we just output the value of "product"
-
Not Synced
so that is an interaction with the user
-
Not Synced
so we are literally just outputting the value of "product"
-
Not Synced
so we output
-
Not Synced
output "product"
-
Not Synced
and we are done!
-
Not Synced
and i can write end
-
Not Synced
for the end of our program
-
Not Synced
and the program will stop running
-
Not Synced
end
-
Not Synced
so this is just a simple flowchart for this simple program
-
Not Synced
and hopefully it helps you appreciate
-
Not Synced
that one little understanding of the program
-
Not Synced
itself if the last two videos didn't help too much
-
Not Synced
and also gives you a simple understanding
-
Not Synced
of how to write a flowchart