Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Computer Programming 12 Lesson 5 - Decision Structure By: Dan Lunney."— Presentation transcript:

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

2 If /Then / Else statement Decision logic structure is used to make a decision that has 2 outcomes: true or false 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 We test which it is by using the if/then/else statement IF THEN ELSE IF THEN ELSE

3 If/Then/Else Flowchart Exit IF Start FALSE TRUE Instructions if conditions are false Instructions if conditions are true

4 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 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 This is called a nested if/then/else

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

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

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

8 Straight Logic Flowchart T T T F F F IF

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

10 Positive Logic Flowchart Start if FALSE TRUE if Instructions Exit

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

12 Negative Logic Flowchart Start if FALSE TRUE if Instructions

13 Sample Problem – Lesson 5 What would the flowcharts and algorithms of the following problem look like in straight logic, positive logic, and negative logic? 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. 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 See sample problem sheet See sample problem sheet See sample problem sheet


Download ppt "Computer Programming 12 Lesson 5 - Decision Structure By: Dan Lunney."

Similar presentations


Ads by Google