Содержание
- 2. Objectives In this chapter, you will learn about: Boolean expressions and the selection structure The relational
- 3. Boolean Expressions and the Selection Structure Boolean expressions can be only true or false Every computer
- 4. Boolean Expressions and the Selection Structure (continued) Dual-alternative (or binary) selection structure Provides an action for
- 5. Boolean Expressions and the Selection Structure (continued) Single-alternative (or unary) selection structure Action is provided for
- 6. Programming Logic and Design, Seventh Edition Figure 4-3 Flowchart and pseudocode for overtime payroll program
- 7. Programming Logic and Design, Seventh Edition Figure 4-3 Flowchart and pseudocode for overtime payroll program (continued)
- 8. Boolean Expressions and the Selection Structure (continued) if-then-else decision if-then clause Holds the action or actions
- 9. Using Relational Comparison Operators Relational comparison operators Six types supported by all modern programming languages Two
- 10. Programming Logic and Design, Seventh Edition Table 4-1 Relational comparison operators
- 11. Using Relational Comparison Operators (continued) Any decision can be made with only three types of comparisons:
- 12. Using Relational Comparison Operators (continued) Programming Logic and Design, Seventh Edition Figure 4-5 Using a negative
- 13. Using Relational Comparison Operators (continued) Programming Logic and Design, Seventh Edition Figure 4-6 Using the positive
- 14. Avoiding a Common Error with Relational Operators Common errors Using the wrong operator Think BIG >
- 15. Understanding AND Logic Compound condition Asks multiple questions before an outcome is determined AND decision Requires
- 16. Programming Logic and Design, Seventh Edition Figure 4-7 Flowchart and pseudocode for cell phone billing program
- 17. Programming Logic and Design, Seventh Edition Figure 4-7 Flowchart and pseudocode for cell phone billing program
- 18. Nesting AND Decisions for Efficiency When nesting decisions Either selection can come first Performance time can
- 19. Using the AND Operator Conditional AND operator Ask two or more questions in a single comparison
- 20. Using the AND Operator (continued) Programming Logic and Design, Seventh Edition Table 4-2 Truth table for
- 21. Programming Logic and Design, Seventh Edition Figure 4-9 Using an AND operator and the logic behind
- 22. Avoiding Common Errors in an AND Selection Second decision must be made entirely within the first
- 23. Understanding OR Logic OR decision Take action when one or the other of two conditions is
- 24. Writing OR Decisions for Efficiency May ask either question first Both produce the same output but
- 25. Using the OR Operator Conditional OR operator Ask two or more questions in a single comparison
- 26. Using the OR Operator (continued) Programming Logic and Design, Seventh Edition Table 4-3 Truth table for
- 27. Programming Logic and Design, Seventh Edition Figure 4-13 Using an OR operator and the logic behind
- 28. Avoiding Common Errors in an OR Selection Second question must be a self-contained structure with one
- 29. Avoiding Common Errors in an OR Selection (continued) Programming Logic and Design, Seventh Edition Figure 4-14
- 30. Avoiding Common Errors in an OR Selection (continued) Programming Logic and Design, Seventh Edition Figure 4-15
- 31. Avoiding Common Errors in an OR Selection (continued) Programming Logic and Design, Seventh Edition Figure 4-16
- 32. Avoiding Common Errors in an OR Selection (continued) Programming Logic and Design, Seventh Edition Figure 4-17
- 33. Avoiding Common Errors in an OR Selection (continued) Programming Logic and Design, Seventh Edition Figure 4-18
- 34. Making Selections within Ranges Range check Compare a variable to a series of values between limits
- 35. Making Selections within Ranges (continued) Programming Logic and Design, Seventh Edition Figure 4-19 Discount rates based
- 36. Programming Logic and Design, Seventh Edition Figure 4-20 Flowchart and pseudocode of logic that selects correct
- 37. Avoiding Common Errors When Using Range Checks Avoid a dead or unreachable path Don’t check for
- 38. Understanding Precedence When Combining AND and OR Operators Combine multiple AND and OR operators in an
- 39. Understanding Precedence When Combining AND and OR Operators (cont’d) When only one of multiple conditions must
- 40. When AND and OR operators are combined in the same statement, AND operators are evaluated first
- 41. Mixing AND and OR operators makes logic more complicated Can avoid mixing AND and OR decisions
- 42. Programming Logic and Design, Seventh Edition Figure 4-23 Nested decisions that determine movie patron discount
- 43. Summary Decisions involve evaluating Boolean expressions Use relational operators to compare values An AND decision requires
- 45. Скачать презентацию