Basic logical blocks
![](/files/latest/en/2302449627/2302449636/1/1710344753778/image-115.png)
Branch blocks
If condition* is true, perform the action
![](/files/latest/en/2302449627/2302449641/1/1710344753839/image-210.png)
If condition* is true, perform an action, else perform another action
![](/files/latest/en/2302449627/2302449640/1/1710344753836/image-39.png)
* Boolean condition - an expression, the result of which is “true” or “false”
You can modify these blocks by adding more conditions to them
![](/files/latest/en/2302449627/2302449639/1/1710344753786/image-14.gif)
Logic AND and OR
![](/files/latest/en/2302449627/2302449638/1/1710344753784/image-46.png)
If at least one of the simple statements connected by the AND operation is false, then the compound statement will also be false
If at least one of the simple statements connected by the OR operation is true, then the compound statement will also be true
Comparison operations
Usually used with numbers. Equality operations can also be used on text
![](/files/latest/en/2302449627/2302449637/1/1710344753781/image-54.png)
You can only compare data of the same type (you can’t compare numbers and text)
True/False
Boolean variable
![](/files/latest/en/2302449627/2302449635/1/1710344753775/image-65.png)
Logical NOT
The logical operation does NOT invert the statement behind it
![](/files/latest/en/2302449627/2302449634/1/1710344753773/image-74.png)
For example, the following expression (however useless but cognitive) will return true
![](/files/latest/en/2302449627/2302449633/1/1710344753770/image-82.png)
Ternary conditional operation
![](/files/latest/en/2302449627/2302449632/1/1710344753766/image-101.png)
A ternary operation can be defined as an operation that returns its second expression depending on the value of the logical expression given by the first expression. The operation algorithm is as follows:
- The boolean expression is evaluated
- If the logical expression is true, then the value of expression 1 is evaluated; otherwise, the value of expression 2 is evaluated
- The computed value is returned
Only one of the expressions is evaluated: expression 1 or expression 2. This corresponds to the principle of lazy evaluation
Example
![](/files/latest/en/2302449627/2302449631/1/1710344753762/image-116.png)
- If both simple buttons are pressed, then change “color” to “blue”, otherwise - “red”
- Set a simple light bulb to the color stored in the “color” variable
Which is equivalent to the following construction
![](/files/latest/en/2302449627/2302449630/1/1710344753758/image-121.png)
True with probability
![](/files/latest/en/2302449627/2302449629/1/1710344753754/image-131.png)
Boolean variable whose truth will depend on the specified probability