Decision Structure and Boolean Logic (T)
Decision Structure and Boolean Logic (T)
Chapter 4
Learning Objectives
At the end of this lecture, students are able to:
LO1: To explain the uses of decision structure and
Boolean logic
LO2: To write pseudo-code to solve problem containing
decisions
Introduction to Decision
Structures
Gaddis, T., Starting Out With Programming Logic and Design, 5 ed, ISBN: 978-0-13-480115-5
Combined Structures
Gaddis, T., Starting Out With Programming Logic and Design, 5 ed, ISBN: 978-0-13-480115-5
Programming Style with Decision
Structure
Gaddis, T., Starting Out With Programming Logic and Design, 5 ed, ISBN: 978-0-13-480115-5
Dual Alternative Decision
Structures
Gaddis, T., Starting Out With Programming Logic and Design, 5 ed, ISBN: 978-0-13-480115-5
Dual Alternative
Print “you
Enter Temp have a
in Celcius fever
TempC
end
>=37
Print “you
are fine”
Enter
TempC
Gaddis, T., Starting Out With Programming Logic and Design, 5 ed, ISBN: 978-0-13-480115-5
Dual Alternative
Gaddis, T., Starting Out With Programming Logic and Design, 5 ed, ISBN: 978-0-13-480115-5
Dual Alternative
Hierarchy Chart
Gaddis, T., Starting Out With Programming Logic and Design, 5 ed, ISBN: 978-0-13-480115-5
Dual Alternative
Flow Chart
Gaddis, T., Starting Out With Programming Logic and Design, 5 ed, ISBN: 978-0-13-480115-5
Dual Alternative
Flow Chart
Gaddis, T., Starting Out With Programming Logic and Design, 5 ed, ISBN: 978-0-13-480115-5
Dual Alternative
Pseudocode
Gaddis, T., Starting Out With Programming Logic and Design, 5 ed, ISBN: 978-0-13-480115-5
Dual Alternative
Pseudocode
Gaddis, T., Starting Out With Programming Logic and Design, 5 ed, ISBN: 978-0-13-480115-5
Dual Alternative
Pseudocode
Gaddis, T., Starting Out With Programming Logic and Design, 5 ed, ISBN: 978-0-13-480115-5
Comparing Strings
Gaddis, T., Starting Out With Programming Logic and Design, 5 ed, ISBN: 978-0-13-480115-5
Comparing Strings
Gaddis, T., Starting Out With Programming Logic and Design, 5 ed, ISBN: 978-0-13-480115-5
Comparing Strings
Example:
Gaddis, T., Starting Out With Programming Logic and Design, 5 ed, ISBN: 978-0-13-480115-5
Nested Decision Structures
Gaddis, T., Starting Out With Programming Logic and Design, 5 ed, ISBN: 978-0-13-480115-5
Nested Decision Structures
Gaddis, T., Starting Out With Programming Logic and Design, 5 ed, ISBN: 978-0-13-480115-5
Nested Decision Structures
Gaddis, T., Starting Out With Programming Logic and Design, 5 ed, ISBN: 978-0-13-480115-5
The Case Structure
Gaddis, T., Starting Out With Programming Logic and Design, 5 ed, ISBN: 978-0-13-480115-5
The Case Structure
Gaddis, T., Starting Out With Programming Logic and Design, 5 ed, ISBN: 978-0-13-480115-5
The Case Structure
Gaddis, T., Starting Out With Programming Logic and Design, 5 ed, ISBN: 978-0-13-480115-5
Logical Operators
Gaddis, T., Starting Out With Programming Logic and Design, 5 ed, ISBN: 978-0-13-480115-5
Logical Operators
AND example
If temperature < 20 AND minutes > 12 Then
Display “The temperature is in the danger zone.”
End If
OR example
If temperature < 20 OR temperature > 100 Then
Display “The temperature is in the danger zone.”
End If
NOT example
If NOT (temperature > 100) Then
Display “This is below the maximum
temperature.”
End If
Gaddis, T., Starting Out With Programming Logic and Design, 5 ed, ISBN: 978-0-13-480115-5
Logical Operators
Truth Table
Gaddis, T., Starting Out With Programming Logic and Design, 5 ed, ISBN: 978-0-13-480115-5
References
Gaddis, T. (2019). Starting Out with Programming Logic
and Design 5th.
ISBN: 978-0-13-480115-5