2-1 Making Decisions Sample assignment statements

Slides:



Advertisements
Similar presentations
Flow of Control Chapter 3.
Advertisements

Chapter 4: Control Structures I (Selection)
Copyright © 2002 Pearson Education, Inc. Slide 1.
Chapter 4 - Control Statements
3-1 Chapter 3 Flow of Control (part a - branching)
Chapter 13 Control Structures. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Control Structures Conditional.
The If Then Else Statement Using JavaScript TIP The If Statement is the fundamental control structure that allows branches in the flow of control in a.
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.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
Pascal Programming Today Chapter 4 1 »Conditional statements allow the execution of one of a number of possible operations. »Conditional statements include:
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
Lecture 6 Flow of Control: Branching Statements COMP1681 / SE15 Introduction to Programming.
Lecture 7 Flow of Control: Branching Statements COMP1681 / SE15 Introduction to Programming.
2-1 Making Decisions Sample assignment statements PayAmount = Hours * Rate PayAmount = 40*Rate + (Hours – 40)*Rate*1.5.
Chapter 4: Control Structures: Selection
1 Selection Structures. 2 Making Decisions Sample assignment statements to figure worker pay with possible overtime PayAmount = Hours * Rate PayAmount.
CPS120: Introduction to Computer Science Decision Making in Programs.
Problem Solving with Decisions
Programming Logic and Design, Second Edition, Comprehensive
Conditionals & boolean operators
1. We’ve learned that our programs are read by the compiler in order, from top to bottom, just as they are written The order of statement execution is.
Logic Disjunction A disjunction is a compound statement formed by combining two simple sentences using the word “OR”. A disjunction is true when at.
CHAPTER 4: Selection Control Structure. Objectives  Use the relational comparison operators  Learn about AND logic  Learn about OR logic  Make selections.
A First Book of ANSI C Fourth Edition Chapter 4 Selection.
CHAPTER 3 CONTROL STRUCTURES ( REPETITION ) I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
Programming 1 DCT 1033 Control Structures I (Selection) if selection statement If..else double selection statement Switch multiple selection statement.
Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement.
Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement.
Chapter 51 Decisions Relational and Logical Operators If Blocks Select Case Blocks.
Chapter 4 Control Structures I. Chapter Objectives Learn about control structures Examine relational and logical operators Explore how to form and evaluate.
Chapter 4 Making Decision Csc 125 C++ programming language Fall 2005.
IT CS 200: C ONDITION Lect. Napat Amphaiphan. T HE ABILITY TO CONTROL THE FLOW OF YOUR PROGRAM, LETTING IT MAKE DECISIONS ON WHAT CODE TO EXECUTE 2.
CPS120: Introduction to Computer Science Decision Making in Programs.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 4 Making Decisions.
Relational Operator and Operations
CNG 140 C Programming (Lecture set 3)
Basics programming concepts-2
AND.
Truth Tables for Negation, Conjunction, and Disjunction
Chapter 3: Decisions and Loops
Sequence, Selection, Iteration The IF Statement
Selection—Making Decisions
Flow of Control.
Chapter 3 Branching Statements
Chapter 5 Decisions. Chapter 5 Decisions ssential uestion: How are Boolean expressions or operators used in everyday life?
Topics The if Statement The if-else Statement Comparing Strings
The order in which statements are executed is called the flow of control. Most of the time, a running program starts at the first programming statement,
Introduction To Robot Decision Making
Topics The if Statement The if-else Statement Comparing Strings
Bools and simple if statements
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:
Chapter 8: More on the Repetition Structure
Visual Basic – Decision Statements
Introduction To Robot Decision Making
Chapter 4: Control Structures I (Selection)
Conditional Logic Presentation Name Course Name
Expressions.
Boolean Expressions to Make Comparisons
Simple Control Structures
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
Truth tables Mrs. Palmer.
Simple Control Structures
OPERATORS AND SELECTION 2
The Selection Structure
Algebra: Variables and Expressions
A3 2.1d To Solve Compound Inequalities
Flow of Control Flow of control is the order in which a program performs actions. Up to this point, the order has been sequential. A branching statement.
Presentation transcript:

2-1 Making Decisions Sample assignment statements PayAmount = Hours * Rate PayAmount = 40*Rate + (Hours – 40)*Rate*1.5

2-2 The IF Statement The most common decision structure is the IF statement. A condition is a boolean expression that evaluates to either true or false. Conditions typically involve one of the six relational operators.

2-2 The IF Statement (cont.)

Simple IF Statements

Solving the Overtime Problem

2-3 Nested IF Statements The term nested IF refers to an IF statement contained within the true or false branch of another IF statement.

2-3 Nested IF Statements (cont.)

Long Distance Billing Problem

2-4 Compound Conditions A compound condition consists of two conditions within parentheses joined by a logical operator. The four most common logical operators are NOT, AND, OR, and XOR.

2-4 Compound Conditions (cont.)

2-4 Compound Conditions (cont.)

Chapter Summary A condition is an expression that evaluates to either true or false. IF statements use conditions to choose between actions. The true and false branches of an IF statement may contain any valid statement, including other IF statements. A compound condition is two or more conditions joined by a logical operator.