We will not discuss about the if and STATEMENT The if any statement executed one set of statements when
the condition is true.
That means the boolean expression is true the if block would get executed.
And a different set of statements when the condition is false.
So if they boolean expression is false.
The program comes to the else clause and then executes these statements.
In the end its clause so the if edited statement allows us to follow two courses of action.
And this is the syntax for the failed statement.
If the boolean expression evaluates to false then all of the statements in the if block are skipped.
And instead all these statements under the else clause are executed.
So consider here an example.
I have an if statement here with this condition the condition checks if the variable colored is equal
to the string.
Green and if this boolean expression evaluates TRUE TRUE IT PRINTS this next go.
And if this boolean expression evaluates true false.
That is the if condition is false then the program comes to the edit class and prints.
This takes
so here in this example I have assigned the text Green to the variable color and I pass the variable
to the if clause and if this is true.
That means if the color is green then those text go is gonna be printed as if this is not true.
This text Stop it will be printed so let's execute this cell.
So since color is assigned to green and since this is true this text is printed now in order to execute
the set of statements in the else clause.
I'm gonna change the code here that is I'm gonna change the boolean expression and I'm going to check
if the color is red and then execute this cell again.
So this time since the color code is not equal to this text it read the if statement does not get executed.
But the program goes to the S Class and print did text here.
Now let's talk about the if a live L statement.
Sometimes there are more than two possibilities and we need more than two conditions so in that case
we can use the if a live L statement and it is used when we need to check multiple conditions
and this is D syntax for the if a live is statement.
A list is an abbreviation for it.
If and there is no limit on the number of a live statement but there should be only one else statement.
So out of all of these blogs it is the if block here and then the Elif Elif again and else blog only
one block of code gets executed.
If the condition is true then the code inside the if block gets executed.
If the condition is false then the next condition is evaluated.
That means the Elif condition is evaluated and if this is false the program checks.
If the next a live condition is true or not and so on.
Finally if all of these conditions it is the if and the Elif conditions are false then the block of
code in the edits clause get executed.
That is if none of the conditions is true then the code inside it gets executed.
So let's look at this example.
I have assigned a text Green to the variable colored and because I have multiple conditions to check
I'm going to use the if elif L statement.
So I'm going to assign the text to green to these variable coloured and then the if clause is one to
check if the color is green or not.
If this is true it's going to print this text Gore and I have one a block which is going to check if
the color is yellow if this is true it's going to print.
We and if the if and a live blog conditions are false.
The control goes to the else block and prints text here.
So let's execute this piece of code.
Since colored is assigned to green the first condition that is the if condition is true and that takes
Toyota's printer.
Now let's change this to yellow and this is going to print the statement in the Elif blah.
Now if I say colored is now red if a live conditions at Fort the ends block get executed.