Boolean Logic in Programming. Boolean Logic Branching and looping routines both contain conditions that are either true or false. In 1854 George Boole.

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)
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
Logical Operators and While Loops CS303E: Elements of Computers and Programming.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection)
1 If Control Construct A mechanism for deciding whether an action should be taken JPC and JWD © 2002 McGraw-Hill, Inc.
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.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection)
Fall 2007ACS-1805 Ron McFadyen1 Boolean functions & expressions A boolean function is one that returns true or false The guidelines for class-level methods.
1 Lecture 7:Control Structures I (Selection) Introduction to Computer Science Spring 2006.
Thursday, December 14, 2006 “Would you tell me, please, which way I ought to go from here?” “That depends a good deal on where you want to get to,” said.
1 Selection Structures. 2 Making Decisions Sample assignment statements to figure worker pay with possible overtime PayAmount = Hours * Rate PayAmount.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
Digital Logic Circuits – Chapter 1 Section 1-3, 1-2.
Copyright © 2012 Pearson Education, Inc. Chapter 2 Beginning Problem-Solving Concepts for the Computer Problem Solving and Programming Concepts 9 th Edition.
Unit 5 – “Watch Out!”. Introduction New Topics Case Structures New Functions Less? Comparison Function Ultrasonic Sensor.
Computer Science 101 The Boolean System. George Boole British mathematician ( ) Boolean algebra –Logic –Set theory –Circuits –Conditions in if.
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.
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
Dale Roberts Program Control using Java - Boolean Expressions Dale Roberts, Lecturer Computer Science, IUPUI Department of.
An Introduction to Programming Using Alice Boolean Logic.
1 © 2000 John Urrutia. All rights reserved. Qbasic Looping Statements & Formatted Output.
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.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
Four Fundamental Pieces Instruction Control Structure Function Expression.
Islamic University Of Gaza, Nael Aburas Data Storage Introduction to computer, 2nd semester, 2010/2011 Mr.Nael Aburas
CHAPTER 4: Selection Control Structure. Objectives  Use the relational comparison operators  Learn about AND logic  Learn about OR logic  Make selections.
Computer Science 1620 boolean. Types so far: Integer char, short, int, long Floating Point float, double, long double String sequence of chars.
Operators Precedence - Operators with the highest precedence will be executed first. Page 54 of the book and Appendix B list C's operator precedence. Parenthesis.
Mathematical Expressions, Conditional Statements, Control Structures
1 Programming in C++ Dale/Weems/Headington Chapter 5 Conditions, Logical Expressions.
Decision Making CMSC 201. Overview Today we will learn about: Boolean expressions Decision making.
1 Flow Control Ifs, loops. 2 Data Type At the lowest level, all data in a computer is written in 1’s and 0’s (binary) How the data gets interpreted, what.
1 Chapter 4, Part 1 If Control Construct A mechanism for deciding whether an action should be taken JPC and JWD © 2002 McGraw-Hill, Inc. Modified by S.
Relational and Boolean Operators CSIS 1595: Fundamentals of Programming and Problem Solving 1.
CONDITIONALS. Boolean values Boolean value is either true or false It is name after the British mathemetician, George Boole who first formulated Boolean.
Programming: Simple Control Structures
Programming: Simple Control Structures MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.
Boolean values Gateway to decision making. Background Our problem-solving solutions so far have the straight-line property –They execute the same statements.
Computer Programming Boolean Logic Trade & Industrial Education
Visual Basic CDA College Limassol Campus COM123 Visual Basic Programming Semester C Lecture:Pelekanou Olga Week 4: Understand and implement Decisions.
DIGITAL ELECTRONICS. Everything in digital world is based on binary system. Numerically it involves only two symbols 0 or 1. –0 = False = No –1 = True.
CHAPTER 3 CONTROL STRUCTURES ( SELECTION ) I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
ICS102 Lecture 8 : Boolean Expressions King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science.
Types, Truth, and Expressions Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Types, Truth, and Expressions Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Random Functions Selection Structure Comparison Operators Logical Operator
CPS120 Introduction to Computer Science
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
4-1 LOGIC OPERATIONS In Chapter 3 we discussed the fact that data inside a computer is stored as patterns of bits. Logic operations refer to those operations.
Expressions and Control Flow in JavaScript
Introduction To Robot Decision Making
JavaScript conditional
2-1 Making Decisions Sample assignment statements
Computers & Programming Languages
Bools and simple if statements
Computer Science 210 Computer Organization
Introduction To Robot Decision Making
Chapter 4: Control Structures I (Selection)
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
ECS15 boolean.
Truth tables Mrs. Palmer.
Factoring if/else code
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.
Conditionals.
Types, Truth, and Expressions
Presentation transcript:

Boolean Logic in Programming

Boolean Logic Branching and looping routines both contain conditions that are either true or false. In 1854 George Boole outlined a system of logic dealing with true and false values. Today, this is called Boolean Logic.

Boolean Logic A form of mathematics in which the only values are true and false. There are three basic operations: –AND –OR –NOT

Boolean Logic AND and OR each require two operands NOT requires one operand When two values are combined using AND, the result is true if both values are true. Result of an OR operation is true if either value is true. Result of a NOT operation is the opposite value

Must be precise How do I specify the following in Boolean logic: “Give me a list of all our offices in Pennsylvania and New Jersey.”

Comparing Values Conditions in branching and looping routines are often based on Boolean expressions that compare values. Example: –“The passenger-side air bag may cause injury to children who are under the age of 12 or who weight less than 48 pounds.” –IF (age < 12 OR weight < 48) THEN do not sit in the front passenger seat

Comparing Values IF (age < 12 OR weight < 48) THEN do not sit in the front passenger seat –Evaluate age < 12 (yields true/false) –Then weight < 48 (yields true/false) –Combine the two values using OR (yields true/false)

Logical Comparison Operators

Boolean Functions True and false values in computing can also come from Boolean functions. A function is a method that returns a value. You can use methods to determine the distance between two objects, etc. A Boolean function returns a true/false value instead of a numeric value.

Example: Boolean Function

Built-in Boolean Functions Is behind is one of many functions built-in to nearly all classes in Alice. Many Boolean functions exist for our use.

Seaplane Example

Seaplane Boolean Functions

Comparison Functions Alice also has comparison functions. These can be found on the world’s function tab. Using AND, OR, and NOT functions together with the comparison functions, we can build arbitrarily complex Boolean expressions.

Comparison functions + Boolean logic functions in Alice

Examples If (age < 12 OR height <= 54) While (aliceLiddel distance to whiteRabbit <= 10) While NOT (target = windmill) OR NOT (target = gazebo) If NOT (seaplane is in front of camera) AND ((time 30)) While numberOfGuesses <= log(range)