Visual programing blocks – Logic

Boolean algebra is a mathematical system that has two values:

  • true
  • false

Boolean values (also called conditions) are used in these control blocks, which contain examples:

One of the many examples from those pages is:

If the value of variable x is greater than 100, the condition is true and the text "What a big number!" is displayed. If the value of x is less than 100, the condition is false and "That's not very big." is displayed.

Boolean values can also be stored in variables and passed on to procedures in the same way as numbers, text or list values.

Blocks

If a block expects a Boolean value as an input, it usually interprets an absent input as false. An example is provided below. Non-Boolean values cannot be directly plugged in where Boolean values are expected, although it is possible (but inadvisable) to store a non-Boolean value in a variable, then plug it into the input. Neither of these practices are recommended, and their behaviour could change in future versions of Blockly.

Values

A single block, with a drop-down menu specifying either true or false can be used to get a boolean value:

Comparisons

There are six comparison operators. Each takes two inputs (usually numbers) and returns a true or false condition depending on how the inputs compare to each other.

The six operators are as follows: is equal to, does not equal, is less than, is less than or equal to, is greater than, is greater than or equal to.

Logical operations

The and block will return true only if both of its two inputs are also true.

The or block will return true if either of its two inputs are true.

not

The not block converts its Boolean input into its opposite. For example, the result of:

is false.

As mentioned above, if no input is provided, a value of true is assumed and the following block produces the value false:

Leaving an input empty is not recommended, however.

Žádné komentáře
Zpět nahoru
Visual programing bloc... | WIKI iTriangle

Nastala chyba

An unknown error occurred

Vrátit se domů

Zpět nahoru