Decision Statements.

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)
Chapter 4 - Control Statements
3-1 Chapter 3 Flow of Control (part a - branching)
Control Flow Statements: Repetition/Looping
As you come in…  Sign in (in back) and pick up  Badge  Name Card – write your first name LARGELY on back  Log in:  Launch/Start Alice  Any questions?
3. S/E with Control Structures 3.1 Relational Operators and Expressions 3.2 If and if-else Statements 3.3 The Type Double 3.4 Program Design with the While.
Making Decisions in Python Sec 9-10 Web Design. Objectives The student will: Understand how to make a decision in Python Understand the structure of an.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
Week 10 Recap CSE 115 Spring For-each loop When we have a collection and want to do something to all elements of that collection we use the for-each.
2-1 Making Decisions Sample assignment statements PayAmount = Hours * Rate PayAmount = 40*Rate + (Hours – 40)*Rate*1.5.
1 Lecture 7:Control Structures I (Selection) Introduction to Computer Science Spring 2006.
Chapter 4: Control Structures: Selection
Execution Control with If/Else and Boolean Functions Example: Single Condition Alice.
Decision Statements. Control Stuctures Sequential Processing Sequential Processing Do In OrderDo In Order Do TogetherDo Together If / Else Statements.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
Execution Control with If/Else and Boolean Functions
Execution Control with If/Else and Boolean Functions Sec 52 Web Design.
Execution Control with If/Else and Boolean Questions Part 1 Alice.
Study Guide For Test Chapter 5, 6,& 7 Test is Friday, May 15th.
ECS 10 10/8. Outline Announcements Homework 2 questions Boolean expressions If/else statements State variables and avoiding sys.exit(…) Example: Coin.
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.
5-1 Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional statements,
Four Fundamental Pieces Instruction Control Structure Function Expression.
Execution Control with If/Else and Boolean Functions Alice.
If…else statements. Boolean Expressions Boolean expression - An expression whose value is either true or false true = 1 false = 0 Datatype: boolean.
Conditions in Java. First…Boolean Operators A boolean data type is always true or false. Boolean operators always return true or false For example: (x.
Control Structures In structured programming, we use three basic control structures: –Sequence –Selection –Repetition So far, we have worked with sequential.
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
Chapter 3: Branching and Program Flow CSCI-UA 0002 – Introduction to Computer Programming Mr. Joel Kemp.
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.
CompSci 4 Chap 6 Sec 2 Sep 30, 2010 Prof. Susan Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were not a Flutterbudget.
Conditionals Conditional statements, called conditionals for short, are statements in the if-then or if-then-else form. Examples: “If the alarm goes off,
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
CS320n –Visual Programming Execution Control with If / Else and Boolean Functions (Slides 6-2-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Computer Science Up Down Controls, Decisions and Random Numbers.
IF STATEMENTS AND BOOLEAN EXPRESSIONS. BOOLEAN EXPRESSIONS Evaluate to a value of true or false Use relational or equivalence operators Boolean operators.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
Control Flow (Python) Dr. José M. Reyes Álamo.
Making Choices with if Statements
Execution Control with If/Else and Boolean Functions
Chapter 3: Decisions and Loops
Sequence, Selection, Iteration The IF Statement
Chapter 5 Decisions. Chapter 5 Decisions ssential uestion: How are Boolean expressions or operators used in everyday life?
If, else, elif.
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,
Simple Control Structures
Lesson 8: Boolean Expressions and "if" Statements
2-1 Making Decisions Sample assignment statements
CS320n –Visual Programming
Loops A portion of a program that repeats a statement or a group of statements is called a loop. The statement or group of statements to be repeated is.
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
HAPPY NEW YEAR! Lesson 7: If-statements unplugged
Design and Implementation
Visual Basic – Decision Statements
Selection Statements.
Programming: Simple Control Structures
Computer Science Core Concepts
Conditional Logic Presentation Name Course Name
Code Refresher Test #1 Topics:
CS2011 Introduction to Programming I Selections (I)
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
Relational Expressions
The Selection Structure
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.
Lecture 7 – Unit 1 – Chatbots Python – For loops + Robustness
Conditionals.
Presentation transcript:

Decision Statements

Control Stuctures Sequential Processing Do In Order Do Together If / Else Statements  Decisions Repetition  Looping

If / Else Statements Make a decision based on the value of a condition (at Runtime) If a condition is True Do “A” Else (meaning the condition is false) Do Nothing Do “B” Race Car Simulator If the car stays on the road, add points to total Else If the car runs off the road, the car explodes If the car crosses the finish line, add bonus points, player wins, display total Else, game over, player loses

Boolean Functions Functions returning a Boolean Value are often used in Decision Statements If the function returns a True Value Do “A” If the function returns a False Value Do Nothing Do “B”

Relational Operators Used in Expressions for If Statements == Equal To != Not Equal To < Less Than > Greater Than <= Less Than or Equal To >= Greater Than or Equal To These will evaluate out to a boolean condition  either True or False

Compound Conditions Compound Conditions can be used in the If Statements Logical Operators And Or Not And  Both conditions Must be true for a true condition Or  Either condition can be true for a true condition Not  the first condition must be true while the 2nd condition must be false

Example Problem 6-2, #11 Write a vocabulary builder to help someone learn the Spanish word for Cat (gato). 3 Spanish words are displayed, if the user clicks on the correct word have the cat say “Si, Si”, if the user clicks on one of the other words have the cat shake it’s head back and forth

World Creation

Boolean Function Write a function (isGato) that returns true if the word “gato” is clicked and returns false otherwise. Parameter – objectClicked – the 3D word clicked by the user

isGato Function

checkAnswer Method Event Handling Method Compound Condition

Link Method to Event

Homework Chapter 6-2 Problems 13, 14, & 16