# Logic¶

Basic logical blocks ## Branch blocks¶

If condition* is true, perform the action If condition* is true, perform an action, else perform another action Note

* Boolean condition - an expression, the result of which is “true” or “false”

You can modify these blocks by adding more conditions to them ## Logic AND and OR¶ 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 You can only compare data of the same type (you can’t compare numbers and text)

## True/False¶

Boolean variable ## Logical NOT¶

The logical operation does NOT invert the statement behind it For example, the following expression (however useless but cognitive) will return true ## Ternary conditional operation¶ 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:

1. The boolean expression is evaluated
2. If the logical expression is true, then the value of expression expression 1 is evaluated; otherwise, the value of expression expression 2 is evaluated
3. The computed value is returned

Note

Only one of the expressions is evaluated: expression 1 or expression 2. This corresponds to the principle of lazy evaluation

### Example¶ 1. If both simple buttons are pressed, then change “color” to “blue”, otherwise - “red”
2. Set a simple light bulb to the color stored in the “color” variable

Which is equivalent to the following construction ## True with probability¶ Boolean variable whose truth will depend on the specified probability