Logic
Last updated
Last updated
Boolean logic is a simple mathematical system that has two values:
true
false
Logic blocks are generally used to control conditional blocks and repeat blocks.
Here's an example:
If the value of the variable temperature
is less than or equal to 0, the condition is true, and the text "Freezing" is printed. If the value of temperature
is greater than 0, the condition is false, and "A thaw" is printed.
Boolean values can also be stored in variables and passed to functions, the same as number, text, and list values.
A block that returns a fixed Boolean value (either true
or false
).
Value (Boolean): Choose true
or false
.
Boolean: The selected Boolean value.
Compares two values using a chosen operator (equals, not equals, less than, greater than, less than or equal, greater than or equal).
Left Value (Number or comparable type)
Right Value (Number or comparable type)
Operator (Enum): =
, ≠
, <
, >
, ≤
, ≥
Boolean: true
if the comparison is satisfied, otherwise false
.
Performs a logical AND operation on two Boolean inputs.
Input A (Boolean)
Input B (Boolean)
Boolean: true
if both inputs are true
, otherwise false
.
Performs a logical OR operation on two Boolean inputs.
Input A (Boolean)
Input B (Boolean)
Boolean: true
if at least one input is true
, otherwise false
.
The not block converts its Boolean input into its opposite.
If no input is provided, a value of true
is assumed, so the following block produces the value false
:
Leaving an input empty is not recommended, however.
Input (Boolean)
Boolean: true
if the input was false
, and false
if the input was true
.
A conditional expression that returns one of two values based on a Boolean condition.
Condition (Boolean)
Value if True (Any type)
Value if False (Any type)
Any type: The value corresponding to the outcome of the condition.
Executes enclosed blocks if the condition is true
.
Condition (Boolean)
Executes one set of blocks if the condition is true
, otherwise executes another set.
Condition (Boolean)
Checks multiple conditions in sequence. Executes the first matching condition’s blocks.
Condition (if) (Boolean)
Condition(s) (else if) (Boolean)
Checks multiple conditions and has a final else
to run if none are met.
Condition (if) (Boolean)
Condition(s) (else if) (Boolean)
Only the plain if
block appears in the toolbox:
To add else if
and else
clauses, the click on the gear icon, which opens a new window:
Drag else if
and else
clauses under the if
block, as well as reordering and removing them. When finished, click on the gear icon, which closes the window, as shown here:
Note that the shapes of the blocks allows any number of else if
subblocks to be added but only up to one else
block.