In this lecture you will learn about the conditional statements in C++.
So the most frequently used conditional statements is if statement here, if true and there are code.
So in its simplest form, the if statement takes a logical expression, true or false, or we can do
for example is empty function like that.
This is not actually is empty function really.
But we can take anything that returns boolean value and give this as parameter.
And if the parameter returns true, the if block will execute.
If not the and if not, then we have else block or else if block the as if block and as block will execute.
So if neither of if we only have the just one if block, then if and our if here is false, then our
code will not execute at all.
So.
And we adhere to the logical expression in a pair of parenthesis and immediately followed by the statement
as executed if the condition is true.
So I want to write some quotes here.
For example, you can hear integer integer a here STD seen here where we will get some.
Input from the keyboard here from the user.
If a greater than ten then.
See out.
Here A is greater than ten.
Beer and.
As you can see.
So let's write our expression, right?
Compile our code and let's see what happens.
So we're going to try up some value eight and we got no output because if BLOCK was not true, so eight
is not greater than ten.
And this block used like it doesn't even dare.
So this if block is passed.
So let's create again, let's run this program again and write, for example, 99.
As you can see here, A is greater than ten and this this code executed.
So you can also use the statement to catch the occasions when the condition is false.
So else here.
Elsie, If this statement is false, then run.
Statement.
So for example std c out.
So if.
Our A number is greater than ten.
Then.
For example.
Within range here of let's add the.
Here with.
Full range and arrested and locked.
Here.
For example one and within range.
So or let's create a is less than than ten.
Here.
And let's fry it, for example five and we will get a e is less than ten.
If a right 99 or for example, 11, we will get a is greater than ten and this code of pluck will execute.
So the condition is a logical expression, as I said earlier, and C++ will convert from numeric types
to bool here.
So here, as I said earlier, zero is false and anything.
In think non zero is true.
Yeah.
So if you are not careful, this can be a source of an error that is not only difficult to notice,
but also can have an unexpected side effects.
So let's create an another quote here.
For example.
Well, it's chaos.
So.
We get, we create an integer, a get user, get input from user and write it to a.
And then if.
E equals.
Or a equals to minus one equals to minus one.
Then.
We will print the message typed minus one.
Here and here we don't need, for now, the smog.
So let's run.
There.
Or let's write.
Let's use this end as called here.
Non minus one.
Here.
Let's write five.
We will get this minus one output here.
If they write minus one here.
Negative one, we will get types.
Negative one.
At which point?
After this.
After we got this output, the loop finishes so if you mistype you may here end up with the code here.
For example, if a equals two minus one, then you will get this code here, for example, five typed
minus one.
So in this case, the assignment operator is used instead of equality operator.
So I want to write it here.
This is equality operator here.
Equality.
Operator.
And this is assignment.
Operator.
So make here be careful when you use the operator, because these mistakes is hard to notice, really.
So the result is that regardless of what you type at the console, the variable A is assigned to minus
one and the signs minus one is not zero.
The condition in the if statement is true, hence the rule clause of the statement is executed.
Sign the variable assigned to minus one.
This may alter logic further on your call.
So the way to avoid this bug is to take advantage of the requirement that in an assignment of the left
hand side must be an l value here minus one here a here.
Let's run this again.
Like to mine and this is non zero one.
So our code started to work correctly again.
So here the logical expression is minus one equal to operator A and signs that this operator is a commutative.
The order of operations doesn't matter.
You get the same result here.
So it doesn't matter if you write a in left or right, you will get the same result here.
Minus one.
Let's write it eight, nine.
Here again.
You will your work will, your code will work correctly.
So in this case here, the assignment has an error value.
Here.
Assignment has an air value on the left hand side, and this will close the compiler here.
An error.
If a write like that, which error named el value required as left operand of assignment.
So your code won't compile if you write like that.