Chapter 5 Decisions. Chapter 5 Decisions ssential uestion: How are Boolean expressions or operators used in everyday life?

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

Chapter 4: Control Structures I (Selection)
A number of MATLAB statements that allow us to control the order in which statements are executed in a program. There are two broad categories of control.
1 Chapter Five Selection and Repetition. 2 Objectives How to make decisions using the if statement How to make decisions using the if-else statement How.
CHAPTER 5: Repetition Control Structure. Objectives  To develop algorithms that use DOWHILE and REPEAT.. UNTIL structures  Introduce a pseudocode for.
Selection (decision) control structure Learning objective
Lesson 5 - Decision Structure By: Dan Lunney
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 9 Decisions, Decisions, Decisions.
 Control structures  Algorithm & flowchart  If statements  While statements.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Conditional Statements Control Structures.
C++ for Engineers and Scientists Third Edition
Programming Logic and Design Fourth Edition, Introductory
Programming Logic and Design Sixth Edition
1 Chapter 4: Selection Structures. In this chapter, you will learn about: – Selection criteria – The if-else statement – Nested if statements – The switch.
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
Programming Logic and Design, Second Edition, Comprehensive
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Flowcharts.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 4 Decision.
CHAPTER 4: Selection Control Structure. Objectives  Use the relational comparison operators  Learn about AND logic  Learn about OR logic  Make selections.
Control Structures By Shyam Gurram. Control Structure In this chapter we have two different types of structures. Conditional Structure Iterative Control.
Programming 1 DCT 1033 Control Structures I (Selection) if selection statement If..else double selection statement Switch multiple selection statement.
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
Chapter 4 Control Structures I. Chapter Objectives Learn about control structures Examine relational and logical operators Explore how to form and evaluate.
An Object-Oriented Approach to Programming Logic and Design Chapter 5 Making Decisions.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 5 Making Decisions.
P ROGRAMMING L OGIC GWDA123 Sharon Kaitner, M.Ed. Winter 2015: Week 2.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
CSE202: Lecture 5The Ohio State University1 Selection Structures.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
C++ for Engineers and Scientists Second Edition Chapter 4 Selection Structures.
Programming Logic and Design Fourth Edition, Introductory Chapter 2 Understanding Structure.
Sensor Information: while loops and Boolean Logic.
11 Making Decisions in a Program Session 2.3. Session Overview  Introduce the idea of an algorithm  Show how a program can make logical decisions based.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
Collision Theory and Logic
CNG 140 C Programming (Lecture set 3)
Chapter 4 Repetition Statements (loops)
Collision Theory and Logic
Making Choices with if Statements
The switch Statement, and Introduction to Looping
Selection—Making Decisions
EGR 2261 Unit 4 Control Structures I: Selection
Microsoft Visual Basic 2005 BASICS
Loops CS140: Introduction to Computing 1 Savitch Chapter 4 Flow of Control: Loops 9/18/13 9/23/13.
Selection By Ramin && Taimoor
Loop Control Structure.
More Selections BIS1523 – Lecture 9.
Outline Altering flow of control Boolean expressions
Computers & Programming Languages
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Objectives After studying this chapter, you should be able to:
Understanding the Three Basic Structures
Coding Concepts (Basics)
Introduction to Problem Solving and Control Statements
Chapter 4 Selection.
Three Special Structures – Case, Do While, and Do Until
Problem Solving and Control Statements
While Loops and If-Else Structures
Computer Science Core Concepts
Chapter 4: Control Structures I (Selection)
ICT Programming Lesson 3:
Decision I (if Statement)
Boolean Expressions to Make Comparisons
Topics discussed in this section:
Using Decision Structures
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
The Selection Structure
Control Structures.
Unit III – Chapter 3 Path Testing.
Presentation transcript:

Chapter 5 Decisions

ssential uestion: How are Boolean expressions or operators used in everyday life?

Terms branch condition error-checking nesting selection sequence

Making Decisions in Code Section 5.1 Making Decisions in Code

Section 5.1 Learning Goal Compare ways to control how a program runs.

Making Decisions in Code Three ways to control how programs run Sequence: program will perform the first line of code first Selection: program can make decisions on which lines of code to execute Repetition: loops

Making Decisions in Code IF…THEN, IF…THEN…ELSE blocks Make decisions, control actions in programs Evaluates expressions (true or false) Block combination provides the program’s logic Operators category: comparison operators, also known as relational operators Result is always true or false

Making Decisions in Code Goodheart-Willcox Publisher IF…THEN and IF…THEN…ELSE statements are used to make decisions and reactions in computer programming.

Making Decisions in Code Condition: expression that can only be either true or false (yes or no) Called Boolean expressions Uses binary logic since there are only two possible outcomes Examples Home alarm systems Car’s lights Bouncing sprite off stage’s edge

Section 5.1 Review When would selection program control be used over sequence program control? Why is a condition called a Boolean expression?

Building Boolean Expressions Section 5.2 Building Boolean Expressions

Section 5.2 Learning Goal Apply operators to Boolean expressions.

Identifying Boolean Expressions Boolean expressions make decisions Look at the algorithm Decision points Branches in the program Branch: point in code where a decision is made and a path selected based on the decision

Identifying Boolean Expressions Goodheart-Willcox Publisher Boolean expressions test conditions to make decisions.

Writing Boolean Expressions Break complex expressions into small steps Use operators to join conditions/outcomes AND operator Expression true if both conditions are true OR operator Expression true if either condition is true

Section 5.2 Review Where are Boolean expressions found in a project’s algorithm? Why should complex expressions be broken down into smaller steps?

Section 5.3 Coding Decisions

Section 5.3 Learning Goal Diagram nested decision-making code statements.

IF…THEN Block Beginning contains the condition to test If the condition is true, Program executes the code contained below within the block If the condition is false, Program will proceed to the next block after the IF…THEN block Use conditional operators when testing multiple conditions Goodheart-Willcox Publisher

IF...THEN…ELSE Block Can be used to offer alternative if condition is false If statement is true, only first block section processed If statement is false, only second block section processed Programming technique for verifying correct user input Goodheart-Willcox Publisher

Creating Nested Decisions Nesting: technique in which one decision is contained within another decision Second decision depends on first decision’s outcome Makes code efficient Processed only until problem is solved Allows for complex response No limit on number of statements nested

Creating Nested Decisions Goodheart-Willcox Publisher Nested statements are created by adding an if then or if then else block into another if then or if then else block.

Checking Calculations Error-checking: programming technique for verifying correct user input Example: user password/security question IF…THEN…ELSE statements used to compare user’s answer to data on file

Section 5.3 Review How can conditional operators be used to test multiple conditions? Describe how nesting is similar to Russian matryoshka dolls. Why is error-checking used in programs?