Boolean Logic Damian Gordon.

Slides:



Advertisements
Similar presentations
Chapter 4 - Control Statements
Advertisements

While loops.
Do-while Loops Programming. COMP102 Prog Fundamentals I: do-while Loops /Slide 2 The do-while Statement l Syntax do action while (condition) l How it.
The "if structure" is used to execute statement(s) only if the given condition is satisfied.
Selection (decision) control structure Learning objective
Section 4.2: Functions that Test Conditions (continued)
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.
Python: Modularisation Damian Gordon. Modularisation Remember the prime checker program:
Branching and Conditions CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Slide Copyright © 2009 Pearson Education, Inc. AND Active Learning Lecture Slides For use with Classroom Response Systems Chapter 3 Logic.
Patriotism in the United States SOL 1.11 Created by Kim Smith.
 In studying digital integrated circuits, one must start with the simplest group of circuit, the SSIs or Small Scale Integrated Circuits. Since these.
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.
Searching Damian Gordon. Google PageRank Damian Gordon.
Logic Disjunction A disjunction is a compound statement formed by combining two simple sentences using the word “OR”. A disjunction is true when at.
Session Three Review & Conditional Control Flow. Java File Hierarchy Projects Packages Classes Methods.
ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.
If…else statements. Boolean Expressions Boolean expression - An expression whose value is either true or false true = 1 false = 0 Datatype: boolean.
Linear Algebra. Circuits The circuits in computers and other input devices have inputs, each of which is either a 0 or 1, the output is also 0s and 1s.
Sorting: Optimising Bubblesort Damian Gordon. Sorting: Bubble Sort If we look at the bubble sort algorithm again:
Control Structures In structured programming, we use three basic control structures: –Sequence –Selection –Repetition So far, we have worked with sequential.
Data Structures: Arrays Damian Gordon. Arrays Imagine we had to record the age of everyone in the class, we could do it declaring a variable for each.
Python: Arrays Damian Gordon. Arrays In Python arrays are sometimes called “lists” or “tuple” but we’ll stick to the more commonly used term “array”.
EVALUATING BASIC LOGIC STATEMENTS INTRO TO SYSTEM DESIGN.
A DPLL example C1:(a  b) C2:(  a   b) C3:(a   c) C4:(c  d  e) C5:(d   e) C6:(  d   f) C7:(f  e) C8:(  f   e) false true a a a=false by.
Python: Sorting - Bubblesort Damian Gordon. Sorting: Bubblesort The simplest algorithm for sort an array is called BUBBLE SORT. It works as follows for.
Sorting: Selection Sort Damian Gordon. Sorting: Selection Sort OK, so we’ve seen a way of sorting that easy for the computer, now let’s look at a ways.
Chapter 8: MuPAD Programming I Conditional Control and Loops MATLAB for Scientist and Engineers Using Symbolic Toolbox.
Logical Operators, Boolean Variables, Random Numbers This template was just too good to let go in one day!
5.04 Apply Decision Making Structures
Traits of a Good Citizen Grade 1 SOL 1.10 Created by: Kim Smith.
Pascal Programming Making decisions - Selection Statements National Certificate Unit 4 Carl Smith.
Prime Numbers Damian Gordon. Prime Numbers So let’s say we want to express the following algorithm: – Read in a number and check if it’s a prime number.
Conditional statements and boolean expressions Arithmetic, relational and logical operators.
Python: Iteration Damian Gordon. Python: Iteration We’ll consider four ways to do iteration: – The WHILE loop – The FOR loop – The DO loop – The LOOP.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
Introduction to Python Damian Gordon e:
if ( condition ) statement; if is a Java reserved word The condition must be a boolean expression. It must evaluate to either true or false.
Selection: CASE Statement Damian Gordon. Selection As well as the IF Statement, another form of SELECTION is the CASE statement.
Session Three Review & Conditional Control Flow. Java File Hierarchy Projects Packages Classes Methods.
Logic Gates.
Pseudocode (Revision)
Linked Lists Damian Gordon.
Expressions and Control Flow in JavaScript
Decision statements. - They can use logic to arrive at desired results
Teaching Computing to GCSE
2-1 Making Decisions Sample assignment statements
The C++ IF Statement Part 2 Copyright © Curt Hill
Bools and simple if statements
Types, Truth, and Expressions (Part 2)
Queues: Implemented using Arrays
Stacks: Implemented using Linked Lists
Three Special Structures – Case, Do While, and Do Until
Simple Statistics on Arrays
Some Common Issues: Iteration
Conditional Logic Presentation Name Course Name
Instructor: Scott Kristjanson CMPT 135 SFU Surrey, Spring 2016
Types, Truth, and Expressions (Part 2)
Sorting Damian Gordon.
ECS15 boolean.
Structured Programming
Circular Queues: Implemented using Arrays
Python: Sorting – Selection Sort
Queues: Implemented using Linked Lists
CIS 720 Lecture 3.
A3 2.1d To Solve Compound Inequalities
CIS 720 Lecture 3.
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.
True or False True or False
Presentation transcript:

Boolean Logic Damian Gordon

Boolean Logic You may have seen Boolean logic in another module already, for this module, we’ll look at three Boolean operations: AND OR NOT

Boolean Logic Boolean operators are used in the conditions of: IF Statements CASE Statements WHILE Loops FOR Loops DO Loops LOOP Loops

Boolean Logic AND Operation The AND operation means that both parts of the condition must be true for the condition to be satisfied. A=TRUE, B=TRUE => A AND B = TRUE A=FALSE, B=TRUE => A AND B = FALSE A=TRUE, B=FALSE => A AND B = FALSE A=FALSE, B=FALSE => A AND B = FALSE

Boolean Logic PROGRAM GetGrade: Read Result; IF (A = 5 AND Age[Index] < Age[Index+1]) THEN PRINT “A is 5”; ENDIF; END.

Boolean Logic PROGRAM GetGrade: Read Result; IF (A = 5 AND Age[Index] < Age[Index+1]) THEN PRINT “A is 5”; ENDIF; END. Both A=5 and Age[Index] < Age[Index+1] must be TRUE to do the THEN part of the statement.

Boolean Logic OR Operation The OR operation means that either (or both) parts of the condition must be true for the condition to be satisfied. A=TRUE, B=TRUE => A OR B = TRUE A=FALSE, B=TRUE => A OR B = TRUE A=TRUE, B=FALSE => A OR B = TRUE A=FALSE, B=FALSE => A OR B = FALSE

Boolean Logic PROGRAM GetGrade: Read Result; IF (A = 5 OR Age[Index] < Age[Index+1]) THEN PRINT “A is 5”; ENDIF; END.

Boolean Logic PROGRAM GetGrade: Read Result; IF (A = 5 OR Age[Index] < Age[Index+1]) THEN PRINT “A is 5”; ENDIF; END. Either or both of A=5 and Age[Index] < Age[Index+1] must be TRUE to do the THEN part of the statement.

Boolean Logic NOT Operation The NOT operation means that the outcome of the condition is inverted. A=TRUE => NOT(A) = FALSE A=FALSE => NOT(A) = TRUE

Boolean Logic PROGRAM GetGrade: Read Result; IF (NOT (A = 5)) THEN PRINT “A is 5”; ENDIF; END.

Boolean Logic PROGRAM GetGrade: Read Result; IF (NOT (A = 5)) THEN PRINT “A is 5”; ENDIF; END. Only when A is not 5 the program will go into the THEN part of the IF statement, when A is 5 the THEN part is skipped.

etc.