Module: Nested conditional statement. Difficult conditions


Problem

2/13

Difficult conditions

Theory Click to read/hide

The previous problem can be solved in a shorter way using complex conditions.  ;

Let's see what it is.
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 is cold outside and it is raining. Two simple conditions (it's cold outside), (it's raining outside) are connected here by AND.

Complex condition - consists of two or more simple relations (conditions) that are combined using logical operations:

 Name As written in C#
And &&
OR ||
NOT !

AND  operation (boolean multiplication) requires two conditions to be met simultaneously .
condition1 && condition2 will only evaluate to true if both simple conditions are true at the same time.

The  OR (logical addition) operation requires at least one of the conditions to be met.
 condition1 ||  condition2  will evaluate to false only if both simple conditions are false at the same time.

Operation NOT  (logical negation)
 ! condition1  will evaluate to false if condition1 is true and vice versa.

Priority of execution of logical operations and relations.
1. Operations in brackets.
2. Operation NOT.
3. Logical relationships >, <, >=, <=, ==, !=.
4. Operation And.
5. Operation OR.
Parentheses are used to change the order of actions.

Boolean variables.
In many programming languages, it is possible to use variables that store boolean values ​​(true/false). In C#, such variables can take the values ​​true (true) or false (false). For example, a program fragment: 
bool a, b;
a = true;
b=false;
Console.WriteLine(a || b);

Will output to screen 1 (which is true -  false is 0).
Boolean variables are of type bool named after the English mathematician George Boole - the creator of the algebra of logic.

Problem

In the previous problem we analyzed, it is necessary to check the condition in which the number must be greater than or equal to 20 and less than or equal to 40. 
You can shorten the previous task using complex conditions.

In the 6th line of the program, instead of the underscore (__), insert the desired logical connective.