Boolean Logic 01-1 Boolean values Are TRUE and FALSE 01-2 - - PowerPoint PPT Presentation

boolean logic
SMART_READER_LITE
LIVE PREVIEW

Boolean Logic 01-1 Boolean values Are TRUE and FALSE 01-2 - - PowerPoint PPT Presentation

Boolean Logic 01-1 Boolean values Are TRUE and FALSE 01-2 Boolean values Are TRUE and FALSE Named after the English mathematician George Boole (1815-64) who developed Boolean algebra 01-3 Boolean values Are TRUE and FALSE


slide-1
SLIDE 1

01-1

Boolean Logic

slide-2
SLIDE 2

01-2

Boolean values

  • Are TRUE and FALSE
slide-3
SLIDE 3

01-3

Boolean values

  • Are TRUE and FALSE

» Named after the English mathematician

George Boole (1815-64) who developed Boolean algebra

slide-4
SLIDE 4

01-4

Boolean values

  • Are TRUE and FALSE
  • They can be established in a number of ways
slide-5
SLIDE 5

01-5

Boolean values

  • Are TRUE and FALSE
  • They can be established in a number of ways

» Declaration

slide-6
SLIDE 6

01-6

Boolean values

  • Are TRUE and FALSE
  • They can be established in a number of ways

» Declaration » Comparison

slide-7
SLIDE 7

01-7

Boolean values

  • Are TRUE and FALSE
  • They can be established in a number of ways

» Declaration » Comparison » Boolean expression

slide-8
SLIDE 8

01-8

Declaration

  • To declare a variable means to create it
slide-9
SLIDE 9

01-9

Declaration

  • To declare a variable means to create it
  • Example:

» In JavaScript declare the variable

doorIsOpen and assert its value is true var doorIsOpen = true;

slide-10
SLIDE 10

01-10

Comparison

  • Comparison operators are used to establish

a relationship between objects of the same type

slide-11
SLIDE 11

01-11

Comparison operators

  • < less than
  • <= less than or equal to
  • === equal to (strict includes operand types)
  • !== not equal to (strict includes operand types)
  • >= greater than or equal to
  • > greater than
slide-12
SLIDE 12

01-12

Comparison operators

  • < less than
  • <= less than or equal to
  • === equal to (strict includes operand types)
  • !== not equal to (strict includes operand types)
  • >= greater than or equal to
  • > greater than

» Comparison operators are infix and binary

slide-13
SLIDE 13

01-13

Comparison operators

  • < less than
  • <= less than or equal to
  • === equal to (strict includes operand types)
  • !== not equal to (strict includes operand types)
  • >= greater than or equal to
  • > greater than

» Comparison operators are infix and binary

> The operator is between (infix) its two

  • perands (binary)
slide-14
SLIDE 14

01-14

Examples

  • maryAge < aliAge
  • year > 1582
  • elephantWeight <= mouseWeight
  • thisYear === 2017
  • thisYear !== leapYear
slide-15
SLIDE 15

01-15

Boolean expression

  • Logical operators can be used to construct

Boolean expressions from Boolean values

slide-16
SLIDE 16

01-16

Boolean expression

  • Logical operators can be used to construct

Boolean expressions from Boolean values

» The operands of the operators must be

Boolean

slide-17
SLIDE 17

01-17

Logical operators

  • && and
  • | | or
  • ! not
slide-18
SLIDE 18

01-18

Boolean expression example

  • Assume the value of year is a calendar year

such as 2017

  • The following expression is true if year is a

leap year in the Gregorian calendar

( year % 4 === 0 // Remainder of year is 0
 // on division by 4
 && // AND
 year % 100 !==0 ) // Remainder of year is not 0 // on division by 100
 | | // OR
 year % 400 === 0 // Remainder of year is 0 
 // on division by 400

slide-19
SLIDE 19

01-19

Using the not operator

! ( year % 100 === 0 ) === ( year % 100 !== 0 )

slide-20
SLIDE 20

01-20

Using the not operator

  • The following expression is true if year is a

leap year in the Gregorian calendar

( year % 4 === 0 // Remainder of year is 0
 // on division by 4
 && // AND
 ! ( year % 100 === 0 ) ) // Remainder of year is not 0 // on division by 100
 | | // OR
 year % 400 === 0 // Remainder of year is 0 
 // on division by 400