Hello and welcome to this video.
In this video I'm going to introduce you to another conditional type of statement called the TELL IF
statement the L if statement is calm like a bridge or a combination of one else statement and an if
statement was kind of like to type of statements combined to one the L if statements are basically used
to check for multiple expressions that are true in your program so they check for several conditions
that are true and if one of them is true it execute the first one it finds and then ignores the rest.
So when you have an if statement if statement would check if a condition is true and then execute the
block of code inside that if block and if the condition is not true it doesn't do anything.
A eal or L if statement is kind of like multiple if statements.
So it gives you options to check for conditions that are true.
They will only execute a block of code as soon as one of the conditions evaluates to true.
It will only execute that block and it will ignore the other code.
So this is what a typical syntax looks like for an L if statement.
So you start with the if statement which will count as the first condition to check if is true and if
it's true you execute the block of code that is indented for that.
If block if that condition is not met it goes onto the l.
If block and checks for the second condition that is true.
If that condition is true it will execute the block of code on the L if condition is very important
to take note of the colon colon tells Python to execute a block of code.
It also tells Python that you are starting a new line of code and the code must be indented indentation
is important so that you know what could block belongs to setting condition.
So let me show you an example of how the L if statement can work.
So I've already got a python file.
I'm just going to create two variables I create variable a and I'll give it a value of seven.
Now create another variable B and I'll give it a value of 8.
Now I can start with my if block so say if the value a is greater than the value B then I'll do my colon
to tell Python that I want to start a new line of code.
Presenter You can see automatically indents it for me so I'm gonna type in a print statement.
I will say print and inside the parentheses of that print function.
I'm going to specify the code that will execute.
So I'm going to say ay ay I'm referring to the value of the variable a no say you can type in anything
you want.
Doesn't really matter is smaller.
And then our exit the string with a comma it's important you add your comma so that the interpreter
knows the difference between a normal variable and a normal string.
All right.
So now this is my if block so you can see by indentation you can tell that this block of code belongs
to this if block.
So now I want to add an else block.
You can add as many L if block if you want.
So you don't necessarily have to have just one.
If you want to have several conditions to test for true you can add as many as you want something else.
If I'm checking on other condition e.g. variable b let me reverse that.
I'll say if the variable B which is eight years is greater than the variable a two column then I want
certain block of code to execute.
So inside onto a print statement and inside that print statement I will specify what I want done.
Let's keep the string and do a comma and say a.
So this is my else if block you can have as many as you want depending on how many conditions you want
to test for that are true.
The code will check the Port St. side beef block first that is a block that will run first is checking
is the value of a which is seven.
Is it greater than B.
It is not.
So that's condition.
This condition is false.
That means this code here will not run.
So it jumps to this other condition the L if block and checks the condition.
Notice I'm using the operators to check.
This is the greater than sign.
This is a greater than.
There are many other operators comparison operators and logical operators you can use a value.
Just use the greater down just for simplicity.
Depending on what condition you are testing you use the appropriate operator.
So this block in the IFF is wrong.
That is it has not tested true.
So that code will not run the code in the L. if is true because B is greater than a B's 8 which is greater
than 7.
So what will happen this block of code will execute c if I press play.
You can see here this code here what I say B is bigger than a B is 8.
It says 8 is bigger than 7 so you can see that block of code executes both the first one does not execute
so you can see the importance of the L.
If so you can add as many L if in your code as required.
I've only just used 2 1 just for simplicity so that's it for this video on the L if conditional statement.
Thank you for watching.
Bye for now.