Nested conditional statement. Difficult conditions


Nested conditional statement
Into "if" blocks and "else" may include any other statements, including other nested conditional statements; the else  statement refers to the nearest previous if.

For example: 
if ( A > 10 ) if ( A > 100 ) cout << "You have a lot of money."; else cout << "You have enough money."; else cout << "You don't have enough money."; To make it easier to understand the program, all "if" blocks and "else" (together with the brackets that delimit them) are shifted to the right by 2-3 characters - such an entry is called a ladder entry.

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.