branching aco101: introduction to computer science
TRANSCRIPT
Branching
ACO101: Introduction to Computer Science
Flowcharting is a way
• Of modeling a system• It is the design of the system and it is what we
do in the Inception and Elaboration phases of a project.
Flowcharts : Review
• Are:
–A schematic representation of a process–And a visual way to describe an
algorithm
Shapes used in flowcharts
Terminators are oval (sometimes you see circles)
Processes are rectangles; they always do something
Decisions are diamonds and they always have a question
These flowcharts are all Examples of Branching
Flowchart for an if statement
Flowchart for an if/else
Nested branching
Multiple alternatives
• Sometimes you wish you had more than one else.
• That is what the else if and the switch is for.
Switch and else if flowchart
So here is the sample “if statement” from Scratch
PsCode is…..
• We will choose a question for the crab to ask.• The seeker [crabby] will ask that question• If the question number is divisible by 5 then
the fairy will give a positive answer to the crab• Other wise she will give a negative answer to
the crab.•
Open Visio and copy this flowchart
So what does that look like in code?
• First – pick a question number and save it to memory
• Second – create a crab object– Make a call to a method called getOneQuestion
• Third – create a fairy object– Make a call to a method called getOneAnswer
Retrieve the question and write it to the screen using the variable
Is the question number divisible by 5??
Now lets set up the branching