"Blackboard" Calculator

Logical expressions

The loop exit condition is a Boolean expression. In addition, logical expressions play a major role in branches, which will be discussed later. To compile Boolean expressions, use the comparison operators and Boolean operations listed in the following table.

Table 2. Comparison operators and logical operations
Comparison operators Logical operations
More (or equal) a>b (a>=b) Logical "And" And
Less than (or equal to) a<b (a<=b) Logical "Or" Or
Equal (not equal) a=b (a<>b) Logical "Negation" Not


The result of the calculation of logical expressions is the logical constants: True and False.

Example. What is greater than  epi or pie?

To find out, the easiest way is to type the following:

= e^pi>pi^e

Calculation result: True, that is, the first expression is greater than the second.

Tip. In order to remember these rules, we denote the Truth through 1, and false — through 0, which is the standard in programming. Then And coincides with the usual multiplication, and therefore this operation is called logical multiplication. Similarly, Or is called logical addition, since for 0 and 1 it coincides with the addition of numbers (with the easily remembered exception: 1+1 = 1).

Rule 4. There should be spaces in the formulas around logical operators.

Example. Players Sam and John in each round randomly either get a point or get nothing. Who will score 10 points first?

Sam = 0
John = 0
    Sam = Sam + random(1)
    John = John + random(1)
until(Sam = 10 Or John = 10)

Recall that the random (1) function returns 0 or 1 with equal probabilities. The condition for exiting the cycle is that at least one of the players scorule 10 points.