Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.

Slides:



Advertisements
Similar presentations
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
Advertisements

Decision Structures Chapter 4. Chapter 4 Objectives To understand: o What values can be stored in a Boolean variable o What sequence structures are and.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Selection Logic Building decision-making into programs.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 1- 1.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 2- 1.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 9- 1.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 18 Indexing Structures for Files.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Fluency with Information Technology Third Edition by Lawrence Snyder Chapter.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 11 Object, Object- Relational, and XML: Concepts, Models, Languages,
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 4- 1.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Visual C++ Programming: Concepts and Projects
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 Part 1 Conditionals and Loops.
CONTROL STATEMENTS Lakhbir Singh(Lect.IT) S.R.S.G.P.C.G. Ludhiana.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition.
Branching and Looping Examples, cont’d. Remember the generic triple jump world…
Programming Logic and Design Fourth Edition, Introductory
Programming Logic and Design Sixth Edition
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 4 Decision Structures and Boolean Logic.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
Decision Structures Chapter 4 Part 2. Chapter 4 Objectives To understand o What relational operators are and how they are used o Boolean logic o Testing.
Chapter 3 Making Decisions
Object-Oriented Programming Using C++ Third Edition Chapter 3 Making Decisions.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
Programming Logic and Design, Second Edition, Comprehensive
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Exam scores by range 3-1.
Four Fundamental Pieces Instruction Control Structure Function Expression.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 4 Decision.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1 Functions.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
© Jalal Kawash Programming Peeking into Computer Science 1.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Making Decisions.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
Chapter 5: Making Decisions
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 4: Making Decisions.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running Types of data.
Summer Computing Workshop. Session 3 Conditional Branching  Conditional branching is used to alter the normal flow of execution depending on the value.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 5 Repetition.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Looping.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Fluency with Information Technology Third Edition by Lawrence Snyder Chapter.
Starting Out With Java 5 (Control Structures to Objects) Chapter 3 By Tony Gaddis Copyright © 2005 Pearson Addison-Wesley. All rights reserved.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 4: Making Decisions 1.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-1 Lecture Objectives To understand: –what values can be stored in a Boolean.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
C++ for Engineers and Scientists Second Edition Chapter 4 Selection Structures.
Chapter 3: Decisions and Loops
Simple Control Structures
Chapter 4: Decision Structures and Boolean Logic
Microsoft Visual Basic 2005 BASICS
Chapter 4: Decision Structures and Boolean Logic
Computer Science Core Concepts
Programming with Alice
Chapter 4: Decision Structures and Boolean Logic
Presentation transcript:

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition by Tony Gaddis Chapter 4: Decision Structures

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Objectives To understand: what values can be stored in a Boolean variable what sequence structures are and when used what decision structures are and when used the difference between dual-alternative and single-alternative decision structures what nested instructions are what relational operators are and how they are used 4-2

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Today’s Agenda 1.Boolean Values 2.The If / Else Decision Structure 3.Nested If / Else Decision Structures 4.Relational Comparisons and Logical Operators 4-3

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Boolean Values True or False? –Boolean values are abstract concepts used in computations? TRUE!

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Boolean Variables Boolean Variables hold only two values True False Initial Value is usually set to be “TRUE”

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Boolean Functions Boolean Functions return one value from the choice of True False Also primitive functions that are Boolean User prompted to answer Yes (true) or No (false)

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The If/Else Decision Structure If/Else decision executes one set of instructions if a Boolean condition is true and a different set if the condition is false All previous instructions have been consecutive (sequence structure), that is: One After The Other

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley If/Else If/Else is a decision structure Instruction tests a condition (which gives a Boolean value) and then based on a true value does task “A” or task “B” if the value was false If the hole is wider than the penguin penguin falls down the hole Else penguin says “Drats!” End If 4-8 TRUE FALSE 4.2

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley If/Else BOTH actions will NOT be performed…only ONE can be! The penguin falling or speaking are instructions that are conditionally executed –They do NOT always execute –Executed only under certain conditions If the hole is wider than the penguin penguin falls down the hole Else penguin says “Drats!” End If 4-9 TRUE FALSE 4.2

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Decision Structure Penguin falls down into the hole Flowchart

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Decision Structure If/Else Tile

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley If/Else Note to empty “slots” in instruction. –IF part –ELSE part The TRUE placeholder is replaced with the Boolean variable or a Boolean function Instructions tiles added to both the IF part and the ELSE part More than one instruction can be added to both the IF and ELSE part! 4-12 Empty If/Else instruction 4.2

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Single-Alternative Decision Structures If/Else is a dual-alternative decision structure Two paths of execution: one following TRUE and the other following FALSE Single-alternative decision structures are similar to the dual-alternative The ELSE part is empty!

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Single-Alternative Decision Structures 4-14 Start Penguin turns to face hole Hole wider than penguin? End Penguin walks to center of hole Penguin falls into hole 4.2 T F

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Nested If/Else Instructions An If/Else instruction is placed inside another If/Else instruction or nested. The inner If/Else executes only if the outer If/Else is true

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Nested If/Else Instructions Start Penguin faces hole Within 2 meters “Too Far!” True Hole wider? “Drats!”Penguin walks Penguin falls in End True False

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Relational Comparisons Relational Operators used to compare values and determine whether relationships such as greater than, less than, or equal to exist Compare two values and determine how they relate to each other OperatorMeaning = Equal to ! =Not equal to >Greater than > =Greater than or equal to <Less than < =Less than or equal to

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Relational Operators Binary…operate on two pieces of data Can use to create conditions in an If/Else instruction Alice uses “a” and “b” for placeholders –Drag the desired tile and replace either the “a” or “b” with a value…such as an object

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Logical Operators Tests more than true/false…can do complex testing! –Test two conditions to see if they BOTH are true! –Or ONLY one condition is true! –Or NEITHER condition is true!