boolean logic
play

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


  1. Boolean Logic 01-1

  2. Boolean values • Are TRUE and FALSE 01-2

  3. Boolean values • Are TRUE and FALSE » Named after the English mathematician George Boole (1815-64) who developed Boolean algebra 01-3

  4. Boolean values • Are TRUE and FALSE • They can be established in a number of ways 01-4

  5. Boolean values • Are TRUE and FALSE • They can be established in a number of ways » Declaration 01-5

  6. Boolean values • Are TRUE and FALSE • They can be established in a number of ways » Declaration » Comparison 01-6

  7. Boolean values • Are TRUE and FALSE • They can be established in a number of ways » Declaration » Comparison » Boolean expression 01-7

  8. Declaration • To declare a variable means to create it 01-8

  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; 01-9

  10. Comparison • Comparison operators are used to establish a relationship between objects of the same type 01-10

  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 01-11

  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 01-12

  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 operands (binary) 01-13

  14. Examples • maryAge < aliAge • year > 1582 • elephantWeight <= mouseWeight • thisYear === 2017 • thisYear !== leapYear 01-14

  15. Boolean expression • Logical operators can be used to construct Boolean expressions from Boolean values 01-15

  16. Boolean expression • Logical operators can be used to construct Boolean expressions from Boolean values » The operands of the operators must be Boolean 01-16

  17. Logical operators • && and • | | or • ! not 01-17

  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 01-18

  19. Using the not operator ! ( year % 100 === 0 ) === ( year % 100 !== 0 ) 01-19

  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 01-20

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend