< Return to Video

Flowchart for the Factorial Program

  • 0:01 - 0:03
    One thing you'll hear or see referred to a lot
  • 0:03 - 0:05
    is something called a flowchart
  • 0:05 - 0:07
    either in computer science, so really when people
  • 0:07 - 0:10
    talk about any type of algorithm or process.
  • 0:10 - 0:11
    So what I thought I would do
  • 0:11 - 0:13
    is for every program I write, is do a simple flowchart
  • 0:13 - 0:14
    maybe I won't do it for every one,
  • 0:14 - 0:14
    but I'll start with one of the basic ones,
  • 0:14 - 0:19
    just so we understand that a flowchart isn't anything fancy.
  • 0:19 - 0:23
    So in this factorial program that we had been looking at in the past couple videos
  • 0:23 - 0:27
    Any flowchart you're just going to be at a starting point
  • 0:27 - 0:32
    I guess, depicted with a circle or oval of some kind.
  • 0:32 - 0:37
    And so we start at this line above this assignment
  • 0:37 - 0:40
    of the number where we actually ask for input from the user.
  • 0:40 - 0:45
    And then after that, we ask for input from
  • 0:45 - 0:46
    the user. This line right here.
  • 0:46 - 0:49
    We are asking for input from the user.
  • 0:49 - 0:51
    So this right over here
  • 0:51 - 0:55
    And we will depict that by a parallelogram.
  • 0:55 - 0:57
    And that is input from the user.
  • 0:57 - 0:58
    And then we'll just say number
  • 0:58 - 1:03
    equals user input.
  • 1:03 - 1:06
    And you can be a little bit loosey-goosey with the terminology
  • 1:06 - 1:09
    here, you're really just trying to tell us what you're doing in this step.
  • 1:09 - 1:12
    The parallellogram tells us that we are somehow interfacing with the user.
  • 1:12 - 1:17
    We're either taking something from the user or we're outputting something to the user.
  • 1:17 - 1:19
    So here, we're saying user input is equal to number.
  • 1:19 - 1:22
    We're assigning number to user input.
  • 1:22 - 1:26
    Then, the next thing we do is just a straight up operation.
  • 1:26 - 1:29
    We just set product to be equal to 1
  • 1:29 - 1:33
    And there we just do that in a rectangle.
  • 1:33 - 1:36
    Product equals 1.
  • 1:36 - 1:41
    Product is equal to one.
  • 1:41 - 1:43
    And then, something interesting is going to happen.
  • 1:43 - 1:47
    We enter into our for loop.
  • 1:47 - 1:49
    And we start with, and what I'm going to do here
  • 1:49 - 1:52
    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
Title:
Flowchart for the Factorial Program
Description:

Flowchart for the factorial program.

more » « less
Video Language:
English
Duration:
05:36

English subtitles

Revisions Compare revisions