Presentation is loading. Please wait.

Presentation is loading. Please wait.

COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 1 Conditional Statements Concepts Covered: Conditional Statements Serially Arranged.

Similar presentations


Presentation on theme: "COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 1 Conditional Statements Concepts Covered: Conditional Statements Serially Arranged."— Presentation transcript:

1 COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 1 Conditional Statements Concepts Covered: Conditional Statements Serially Arranged Conditionals Nested Conditionals Boolean Expressions Part 1 Module 2

2 COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 2 Conditional Statements Concept: Conditional Statements

3 COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 3 “control flow” and sequential execution Open the trash lid Drop empty can in trash Close trash lid

4 COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 4 “control flow” and conditional execution Open the trash lid Drop empty can in trash Close trash lid Is the trashcan’s lid already up? YES TRUE NO FALSE

5 COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 5 IF-THEN vs. IF-THEN-ELSE statements Open the trash lid Drop empty can in trash Close trash lid Is the trashcan’s lid already up? YES TRUE NO FALSE Yell: “Who left the trash open!!!???”

6 COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 6 Flowcharts vs. Pseudo Code Open the trash lid Drop empty can in trash Close trash lid Is the trashcan’s lid already up? YES TRUE NO FALSE IF THEN ELSE ENDIF

7 COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 7 Conditional Statements Application: Serially Arranged Conditionals

8 COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 8 Serial Arrangements code #1a code #2a code #1b Condition #1 Condition #2 code #2b code #3

9 COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 9 Conditional Statements Application: Nested Conditionals

10 COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 10 Nested Arrangements Code #1a Code #2a Code #1b Condition #1 Condition #2 Code #2b Code #3 Condition #3

11 COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 11 Conditional Statements Concept: Boolean Expressions

12 COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 12 What’s in a conditional expression Open the trash lid Drop empty can in trash Close trash lid Is the trashcan’s lid already up? YES TRUE NO FALSE What is a boolean expression? evaluates into TRUE or FALSE only e.g. Comparing variables / values a < b a <= 3 + b a + b >= 999

13 COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 13 What’s in a conditional expression Open the trash lid Drop empty can in trash Close trash lid Is the trashcan’s lid already up? YES TRUE NO FALSE We can have several terms in a conditional expression ( a 0) NOT ( a < b ) Do not assume left to right evaluation Do not assume lazy evaluation Until you KNOW your programming language specifics

14 COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 14 Concept of Truth Table ( a 0) ( a 0 )NOT ( a < b )

15 COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 15 Advices Open the trash lid Drop empty can in trash Close trash lid Is the trashcan’s lid already up? YES TRUE NO FALSE ( a 0) NOT ( a < b ) Do not assume left to right evaluation Do not assume lazy evaluation Until you KNOW your programming language specifics

16 COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 16 Multi-terms Boolean expressions to simplify Display: “OK” Display: “done” (a 0) YES TRUE NO FALSE IF ( a 0) THEN display “OK” ELSE display “KO” ENDIF display “done” Display: “KO”

17 COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 17 Multi-terms Boolean expressions to simplify Display: “OK” Display: “done” (a<b) YES TRUE NO FALSE IF ( a < b ) THEN IF ( a > 0) THEN display “OK” ELSE display “KO” ENDIF ELSE display “KO” ENDIF display “done” Display: “KO” (a>0) Display: “KO” YES TRUE NO FALSE

18 COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 18 Multi-terms Boolean expressions to simplify Display: “OK” Display: “done” (a 0) YES TRUE NO FALSE IF ( a 0) THEN display “OK” ELSE display “KO” ENDIF display “done” Display: “KO”

19 COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 19 Multi-terms Boolean expressions to simplify Display: “OK” Display: “done” (a<b) YES TRUE NO FALSE IF ( a < b ) THEN display “OK” ELSE IF ( a > 0) THEN display “OK” ELSE display “KO” ENDIF display “done” Display: “KO” (a>0) Display: “OK” YES TRUE NO FALSE

20 COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 20 Multi-terms Boolean expressions to simplify Display: “OK” Display: “done” (a 0) YES TRUE NO FALSE IF ( a 0) THEN display “OK” ELSE display “KO” ENDIF display “done” Display: “KO”

21 COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 21 Multi-terms Boolean expressions to simplify KO Display: “done” (a<b) YES TRUE NO FALSE IF ( a < b ) THEN IF ( a>0 ) THEN display “KO” ELSEdisplay “OK” ENDIF ELSE IF ( a > 0) THEN display “OK” ELSE display “KO” ENDIF display “done” KO (a>0) OK YES TRUE NO FALSE (a>0) YES TRUE NO FALSE OK


Download ppt "COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 1 Conditional Statements Concepts Covered: Conditional Statements Serially Arranged."

Similar presentations


Ads by Google