Welcome back in this video, we are going to use if statements and we are going to finally make use
of what we've learned so far, for example, the comparison operators, which are very useful when it
comes to if statements.
So we at this comparison operator, we said five, equal, equal three.
And then if that was true, we can now go ahead and execute something.
So now let's go ahead and create an if statement here.
And before we do so, I'm going to create a little variable called height person one.
And it's going to be something like 170.
And then.
Maybe I should be written correctly, and then I have another one height.
Person two should be something like one hundred and.
Eighty nine.
All right, so these are centimeters.
For those of you who aren't aware of what I'm talking about, so one hundred and seventy centimeters
and one hundred eighty nine centimeters, I think that's something like five.
Seven or five, eight or something like that.
And then this should be, um, six three in terms of feet and inches.
All right.
So these are the two height person, height person one and height person two.
So we have two people and we want to execute something based on a condition.
So if person one is taller than person to.
Then we're going to use raw force in order to beat it.
Let's say we have a fight between two people and now we have to decide what kind of technique we want
him to use.
So let's say our fighter is 170 and the opponent is 189.
So what shall we do?
Shall we either use raw force or shall we use technique?
Of course, a combination of both will be useful, but then we're going to check if height person one
is greater than height.
Person two, I simply want to print something like use raw force.
All right, so let's say let's assume that if someone is taller than he's also going to be stronger
because he's going to have more weight and that is going to be very useful in a one on one fight.
But now.
If we execute this line of Coke, we will see that pretty much nothing will happen because the condition
isn't met, so we have this condition of hide person.
One shall be created in high person two.
But if you look at the values, we will see that that is not true because 170 isn't higher than 189.
So we can see we get nothing here printed.
So now let's say the other way around.
What shall happen if I'd person one is less than high person two?
Well, that's something that we can use with an else statement.
OK.
So in this case, it's either if or else.
So if this condition is met, then execute the code that is within those curly brackets.
And if the condition is not met, then run the else block, which means run the cult, which is within
those curly brackets.
So here I'm just going to say use technique.
All right.
So now let's run this again and see if anything will be printed whatsoever.
And we can see it says use technique.
So because our personal one was smaller than the other one, we advise him to use his best techniques
instead of trying to apply real force when fighting one on one because we're one hell of a coach and
want only the best for our fighter.
But what shall happen if they are both the same size?
So let's say we have the situation where both are actually the same size.
Is there any special advice that we can give our fighter, even though in this example, it's rather
weird to have such a situation?
But let's just say we have this other.
Condition.
So what you can do is you can have an else, if so, there are three different types of checks.
So the if check, then the elusive check.
And then finally the LS, which is not really a check, but which is a code that will be executed as
a default if none of the above are true.
So what does that even mean?
Well, let's say we have an LS if in between here.
So me show you.
So we have an else, if again, with a condition.
So here I'm going to say that those two have the same height.
So equal, equal.
All right.
So we had this first condition here, which was high person, one greater than hot person, too.
Then we had the second condition here, which was high person.
One is equal to high person two when it comes to his size, and then we can execute some code if that
condition is met in here.
So let's just say something like use your power technique one three three seven, something like that.
So the fighter has this power technique, and it's very useful against people who are the same height
as he is.
So you should use that technique.
But then we have this else block, which will be executed if none of the above are true.
So if neither this if statement or this condition here is true nor this condition here is true, then
else block will be executed.
So then the text use technique will be executed instead.
Now, the cool thing is you can have as many lives as you want, so we could go ahead and check if the
height of person one is greater than 150 and execute some coat, then check if what what should happen
if the person is smaller than 140 or all kinds of combinations that we can think of, even though we
have to be careful that certain conditions don't overlap with each other because if they overlap, then
one of them will be useless.
OK, so what we have here, if we execute this, let's say when the person's more personal one in person
two are both 170, then it should display use your power technique one three three seven.
So that we are, it says use your power technique one three three seven.
So let's say want the person to is smaller than the person one, then it should say use.
Air Force.
So that we are use your force.
All right.
And what you see here.
So this whole, if elusive of stuff is a control flow and we're using if statements here now a little
challenge for you.
Please go ahead and create an if else, if else, if else block where the first age check will be at
greater equal.
21.
And if that's the case, then it should write something like or print something like you may drink in
the US, then LS.
If the age is greater equal than 18, then you may vote.
And if somebody is older than 16, you may drive.
And then finally, if none of the above is true, then it should print something like you were too young.
So try to use this kind of structure to print those different statements based on a variable called
age that you, of course, also need to create.
So go ahead and try that.
All right.
So I hope you pass the video, so I'm going to create this variable called H.
And actually, I'm not going to change it so I could go ahead and use a vowel here.
So the variable will be h and then I use an if statement here.
If age was greater equal 21.
Then I want to print something saying, now you may drink in the US because in other countries, you
may drink before that, right?
If you do that, then in our case, of course, this will not be printed because age is not greater
than 21.
Now let's have another check.
So else, if the age is greater, equal.
18.
So what should be printed if that's the case?
Well, let's print something like you may vote now.
All right, Prindle, and you may vote no, and then we have another check.
Age creator equal 16 And then in the US, you may drive so poor and Dylan, you may drive now.
Of course, he knew the license for that, but at least you can make the license or do the license at
this point and then you can use it.
And then finally, we have an LS block, which will be executed if none of the above is true, which
means if the person is.
15 or younger than it should say something like?
You're too young to do whatever.
All right.
So if we run this, you probably already guessed it, it will print.
You may drive now because our age is 17.
All right, so let's run this, and there we are.
So it says you may drive now.
Now, if the age is, let's say, 31 as I am.
You can see it says now you may drink in the US.
All right, so of course, I can do all of the others information as well, so I also may vote.
I also may drive now and so forth.
Of course, I could adjust the print statements here accordingly.
But this is the latest thing, so to speak, that I can do due to my age.
All right.
So we have this, if else, if else blocked, that we can use in order to execute stuff when certain
conditions are met.
Now, by the way, a thing that you can also do if you have a very basic if statement.
So let's say you only have one line of code that follows a condition, so age is greater equal.
30.
Then you can just go ahead and do or add the text in the next line, you're over 30.
All right, so that's something that you can, of course, also do directly.
So just one line of code without having these extra curly brackets around it.
So if you see anything like that, that's what it does.
But you have to be careful because in the next line.
So if I add something like this in the next line?
This line will not be part of this if statement, so it will be executed either way.
So be careful here.
All right.
So these are the if statements and in the next video, we're going to look at when.
Because you might see already that it's complaining.
So it says Cascade, if should be replaced with when.
So let's do that in the next video.
So see you there.