The previous problem can be solved in a shorter way using complex conditions.
Let's understand what is COMPLEX CONDITIONS
The simplest conditions consist of one relation (greater than, less than, etc.). But sometimes it is necessary to combine simple conditions into more complex ones, for example: it's cold outside and it's raining. Two simple conditions (it's cold outside), (it's raining outside) are connected here by the copula I.
COMPLEX CONDITION - consists of two or more simple relations (conditions) that are combined using logical operations
AND - logical multiplication - written in Pascal as and
OR - logical addition - written in Pascal as < strong>or
NOT - logical negation - written in Pascal as not
Operation AND - requires simultaneous fulfillment of two conditions
condition 1 and condition 2 - will be true only if both simple conditions are true at the same time
moreover, in the Pascal programming language - if condition 1 is false, then condition 2 will not be checked
The operation OR - requires at least one of the conditions
condition 1 or condition 2 - will evaluate to false only if both simple conditions are false at the same time
moreover, in the Pascal programming language - if condition 1 is true, then condition 2 will not be checked
Operation NOT
not condition 1 - will evaluate to false, condition 1 is true and vice versa
For example, the following two conditions are equivalent: A > B and not (A <= B)
PRIORITY OF EXECUTION OF LOGICAL OPERATIONS AND RELATIONSHIPS
1) operations in brackets
2) operation NOT
3) operation AND
4) OR operation
5) logical relations >, <, >=, <=, =, <>
Parentheses are used to change the order of actions
BOOL VARIABLES
In many programming languages, it is possible to use variables that store boolean values ("true"/"false"). In Pascal, such variables can take the values True (true) or False (false). For example, a program fragment
var a, b: boolean;
begin
a := True;
b := False;
writeln(a or b);
end.
Will display True
Boolean variables are of type
boolean
, named after the English mathematician George Boole, the creator of the algebra of logic.