At the very lowest level, computer circuitry is made of wires, and each wire is either on or off. So the only operations that can be performed at that lowest level are those that operate on single-bit values (just ones and zeros, that is, just ons and offs). These are called logical (or Boolean) functions. (They're predicates, because their range is Booleans, but these are special in that their domain is also Booleans.) There are three Boolean functions in the Operators palette:
True
or False
) as inputs and report a new Boolean value as output. When you use Boolean functions in a program, though, the inputs will usually be expressions such as .
Instead of dragging a true
or false
block into the input slot of an and
, or
, or not
block, you can click the empty input slot to control a true
/false
toggle:
The and
and not
blocks work exactly the way you'd expect from the meanings of those words in English:
true
, and any other combination of inputs reports false
.or
is a little different in computer science. In English, the word "or" has two different meanings:
or
?AND,
OR, and
NOTand will work exactly the same way as they do in Snap!.
between?
will include the two boundary inputs or not.between?
to create a script that lets you write on the stage in three colors (depending on the height on the stage), using your mouse.true
if num is less than or equal to 23.
true
?
true
and false
), there are only four combinations of inputs for a two-input Boolean operator. Here are the four combinations shown with the or
operator:or
, the four combinations report true
, true
, true
, and false
in that order. (Check for yourself that this is true.) So, you can represent the or
function as TTTF (using T and F as abbreviations for true
and false
). What are the four letters for the and
function? (Assume the same ordering of the inputs: TT, TF, FT, and FF as shown above with or
.) or
function) is useful, but TTTT is not useful (why not?). Which of the possible two-input Boolean operators do you think would be useful? Discuss why.