# Lesson 5 - Decision Structure By: Dan Lunney

## Presentation on theme: "Lesson 5 - Decision Structure By: Dan Lunney"— Presentation transcript:

Lesson 5 - Decision Structure By: Dan Lunney
Computer Programming 12 Lesson 5 - Decision Structure By: Dan Lunney

If /Then / Else statement
Decision logic structure is used to make a decision that has 2 outcomes: true or false We test which it is by using the if/then/else statement IF <condition> THEN <True set of instructions> ELSE <False set of instructions>

If/Then/Else Flowchart
Start IF <condition (s)> TRUE FALSE Instructions if conditions are false Instructions if conditions are true Exit

Nested If/Then/Else We can have a second if/then/else statement as the set of instructions for the True and/or False condition of another if/the/else statement This is called a nested if/then/else

Nested If/Then/Else Flowchart
Start FALSE TRUE if FALSE TRUE if Instructions Instructions Instructions

Three Types of Logic Straight-through (no else part) Positive Logic
Negative Logic

Straight-Through Logic
All if statements are executed sequentially There is no ELSE branch to be executed This type of logic is the least efficient because we need to write a code statement for every possible decision

Straight Logic Flowchart
IF F T IF F T IF F

Positive Logic Most common type as this is how we think
Continues to processing decisions until a decision is true then it stops executing

Positive Logic Flowchart
Start TRUE FALSE if TRUE FALSE if Instructions Instructions Instructions Exit

Negative Logic Works the opposite as Positive Logic
Continues to process decisions until a decision is false then it stops executing

Negative Logic Flowchart
Start FALSE TRUE if FALSE TRUE if Instructions Instructions Instructions

Sample Problem – Lesson 5
What would the flowcharts and algorithms of the following problem look like in straight logic, positive logic, and negative logic? People pay \$7 for movies if they are under 16, \$10 if they are between 16 and 65, and they pay \$5 if they are greater than 65. See sample problem sheet