-
Sometimes we want to ask questions about data. For example, is
x
greater thany
? Is one string equal to another? These questions can’t be answered with Numbers. Instead, they are answered with a new data type called a Boolean. -
video games use Booleans for many things: asking when a player’s health is equal to zero, whether two characters are close enough to bump into one another, or if a character’s coordinates put it off the edge of the screen.
-
A Boolean value is either
true
orfalse
. Unlike Numbers, Strings, and Images, Booleans have only two possible values. -
You already know some functions that produce Booleans, such as
<
and>
! Our programming language has them, too:(< 3 4)
,(> 10 2)
, and(= -10 19)
. -
We also have ways of writing Compound Inequalities, so we can ask more complicated questions using the
and
andor
functions.-
(and (> 3 4) (< 10 2))
translates to "three is greater than four and ten is less than two". This will evaluate tofalse
, since theand
function requires that both sub-expressions betrue
. -
(or (> 3 4) (< 10 2))
, which translates to "three is greater than four or ten is less than two". This will evaluate totrue
, since theor
function only requires that one sub-expression betrue
.
-
-
The Circles of Evaluation work the same way with Booleans that they do with Numbers, Strings and Images:
and > 3 4 < 10 2 (and (> 3 4) (< 10 2))or > 3 4 < 10 2 (or (> 3 4) (< 10 2))
These materials were developed partly through support of the National Science Foundation, (awards 1042210, 1535276, 1648684, and 1738598). Bootstrap by the Bootstrap Community is licensed under a Creative Commons 4.0 Unported License. This license does not grant permission to run training or professional development. Offering training or professional development with materials substantially derived from Bootstrap must be approved in writing by a Bootstrap Director. Permissions beyond the scope of this license, such as to run training, may be available by contacting contact@BootstrapWorld.org.