Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fall 2007ACS-1805 Ron McFadyen1 Boolean functions & expressions A boolean function is one that returns true or false The guidelines for class-level methods.

Similar presentations


Presentation on theme: "Fall 2007ACS-1805 Ron McFadyen1 Boolean functions & expressions A boolean function is one that returns true or false The guidelines for class-level methods."— Presentation transcript:

1 Fall 2007ACS-1805 Ron McFadyen1 Boolean functions & expressions A boolean function is one that returns true or false The guidelines for class-level methods also apply to class- level functions: No references to other objects. No references to world-level functions you have written, but built-in world-level functions are fine to use

2 Fall 2007ACS-1805 Ron McFadyen2 Boolean expressions Expressions like a==b test two operands and return a value of true or false. Boolean expressions are used in while, if expressions, … A boolean function has returns like: Boolean operators not, and, or can be expressed in tabular form a!=b means “a not equal to b”

3 Fall 2007ACS-1805 Ron McFadyen3 Boolean expressions These are simple boolean expressions that are either true of false What is the phrase: possiblePhilosopher = who ?

4 Fall 2007ACS-1805 Ron McFadyen4 Boolean expressions Not operator anot a truefalse true

5 Fall 2007ACS-1805 Ron McFadyen5 Boolean expressions And operator ba and b true false a true false

6 Fall 2007ACS-1805 Ron McFadyen6 Boolean expressions Or operator ba or b true falsetrue a false … In alice, we compose boolean expressions that are of a nested form:

7 Fall 2007ACS-1805 Ron McFadyen7 Boolean expressions The text has a couple of examples on page 167: 1. either (both(who==homer) and (who.color==blue)) or (who.color==black) or both Consider: And then we develop: How is this interpreted, how is it developed?

8 Fall 2007ACS-1805 Ron McFadyen8 Boolean expressions The text has a couple of examples on page 167: 2. both(who==homer) and (either who.color==blue or who.color==black or both) Consider: And then we develop: How is this interpreted, how is it developed?

9 Fall 2007ACS-1805 Ron McFadyen9 Boolean expressions The text has a couple of examples on page 167: 1. either (both(who==homer) and (who.color==blue)) or (who.color==black) or both 2. both(who==homer) and (either who.color==blue or who.color==black or both) Are they the same? Are they different?

10 Fall 2007ACS-1805 Ron McFadyen10 Ch6 ends with Random Functions There are two random functions in alice: 1.Choose true …. Returns a boolean value 2.Random number Returns a number as you prescribe


Download ppt "Fall 2007ACS-1805 Ron McFadyen1 Boolean functions & expressions A boolean function is one that returns true or false The guidelines for class-level methods."

Similar presentations


Ads by Google