Hello and welcome.
Today, we will kick off with a new topic, which will be if conditions, statements, if conditions
is a meaningful part in programming in general and in Python specifically, if conditions have strong
connections also to the next topic, which will be Loop's.
And let's go straight ahead for the theoretical part definition.
So if is if condition is an ability for decision making.
In other words, sometimes in our call we would like to take a certain variable or a certain collection
and decide what happens if the value that we are dealing with will be will be equals for something or
it will be bigger than something.
And what will happen if our if condition, meaning our question will be true, then we would submit
a certain part of the code.
And if the result will be false, we would like a different code to run.
So this is decision making in summary.
So if condition is an ability for decision making and for that if conditional statement was created,
also known as if else statement, meaning if you encounter this term, so this term and if conditions
is the same.
So in computer science and if statement gives it an ability, the ability to execute a bulk of code
for a choice for your choice, only if a certain condition is satisfied.
This happens as the result of an if statement is a true or false boolean value, meaning the output
of an condition could be only two options, true or false.
And then we can decide what happens if the value of the if condition is true and what will happen if
it's false.
So let's start off with a simple syntax example here.
We can see and if conditional example or this part right here.
So first of all, we're defining here a variable X and it's equal to three.
And then we're asking the if condition right here.
It's right in here if X is larger than four.
So if you'd like to cast it, as you might say, to human language, this is a question.
This is a question we're asking is if bigger than for it's a question and if the answer is true.
So you can see an indent right here.
This is the intent of the if so if the output here is true, boolean boolean value true.
So please print out this bulk of code.
And if it's false, then the code flow will go straight ahead to the else part and it will print the
value.
No, it's very simple.
All right.
So it's a question if the answer is yes.
So print this one if the answer is true, to be more accurate.
So print this bulk of code and if it's false, then go get out of the F and go to what you have in the
else.
This is like the default exit point, meaning if this value ratio is false, meaning if the value right
here is false, then go to the default exit point, which will be the errors and run what you have under
the else.
So this is a quick brief.
All right.
Right here.
Let me just fix it.
This and this, yeah, so let's I'm going to repeat several times on what we just discussed right there,
one of the ones of you that got the hang of it, just go and play.
Fast forward the following minute.
But for those of you who have trouble to get the concept, I'm going to repeat it several times so we'd
go deeper into your DNA.
All right.
So follow steps.
So we have here also a sketch of the flow, the call flow.
So what happens here?
Basically, I'm explaining what happened here.
All right.
So first of all, we start the program, we start the class, we run the class that this bulk of code
is in it.
So we started.
Then we encounter and if condition.
Right.
This is the yellow part right here.
And then there is a question in the if condition if the answer is to run the code back inside the if
meaning.
Meaning print.
Yes.
And if the answer is false, then run the code back inside or else.
All right.
So you have the same explanation right here.
So what actually like what?
Like physically will be the output of this one.
So we declared here X equals three, then we ask X bigger than for obviously the output of this one
is false.
So the output of this whole F condition would be print will get the output.
No.
All right.
All right, so in this case, Perrino will be executed as the condition we have, it's bigger than four
is false.
So the court under house will run because house is used as a default exit point for the state for if
the statement is not true.
Pretty easy, right?
We have just two options here.
This or this.
That's it.
That's the simple.
If so, if you get the hang of this one, you now know what or if statements are right.
And from here, let's go and talk about we have the ALS here, but we also have a term which is ayliffe.
All right.
We have ALS and we have Ayliffe.
So what is the difference between them?
What's the purpose of else?
We know already, but what's the purpose of our if we don't know yet?
So let's hear off again with the theory and see an example straight ahead.
So as we saw in the syntax example above, that if statement returns a false value, we are only the
code that is indented inside the else.
Right, which was print.
No, but on that's in there, we hope.
And we have only one condition.
We asked a single question and we have only two options.
We can run either prints or print.
No, we don't have any other options right here.
All right.
So we have only one condition.
It's either true and then we print, then we execute this one or it's a false and then we execute this
one, right.
But what if we have lots of conditions to take into consideration and not only one, then we should
use our if as well.
And then we ship its duplicates are.
All right, so Aliev is for all mede conditions while alse is for the last condition that he is used
as in default exit point for the condition part.
And let's see an example for this.
All right.
Right here.
We also are going to have X equals three.
Then we ask a question.
Does X is bigger?
Is is bigger than four.
All right.
So X is not bigger than four.
So we have a false here.
So this would not be executed because false is not executed, is never executed.
Then we will like to ask another question, Ali, if X bigger than five.
All right.
So it's like a continuation of this if.
All right.
So if by the way, I wrote here in the sketch bolded in yellow elif stands for or else if I so have
if x bigger than for false.
So this one would not be executed then we ask.
Alice, if it's bigger than five, we just go with the flow from top to bottom, right?
So after that we ask else if it's bigger than five, also false, then we ask again, else if it's bigger
than 15.
Also, it falls here.
Also a false.
Right, and then all of these values, all these Output's values were false, boolean false, and then
we got to the last one, which is alse, and then we just go straight ahead.
You print five and the only code that would be executed right here among these these conditions right
here, the only one that would be executed is print five right here.
And why?
The reason is the reason is for the last condition that is used as a default exit point, meaning if
all of these are false, then our code would run what we have here in else.
This is the default exit point.
If all of these are output's are false, then else will be executed.
All right.
And right here, let's see the sketch.
So this is the flow that we have just went over and what we basically see here is the start while we
execute the class, that the cold is in it.
And then we have the first if condition.
If the F if condition is true, then run the cold ball inside.
If this is this part is the same as the previous part, then if it's false, basically, if like we
have a true so the cold exits the if condition it exits it and continues to the next block of cold,
the if condition is completed.
If we have a true value we just continue on.
All right.
But if it's a false then we start a different flow here.
As you can see on the left, we first check is the first el.
If true, if it's true, round the ball, cold inside the first hour, if then if it's a false all right
then go to the second el if.
A condition, and then if that one is true, then Rhonda called in the second ayliffe, if this one
is false, then go straight ahead to the third one.
And if the third one is false, then go inside the default exit point.
Let me just quickly add here the missing parts, because we also need to mention here that what happens,
whether we have a false value for these you else ifs all right like that.
And also mention here that.
What happens if we have a true value for the house?
If so, let me just put it right here.
Yeah.
So I think it's a bit self explanatory because we basically have the same structure and a basic if and
also in an L if the difference is that in our if we just have several examples of several conditions
asked and whether in the flow we get a true for one of them.
So the the code just stops dealing with the if statement just goes on further in the code.
All right.
So the flow goes again like this.
We start the code which first check the main if condition.
If the main condition is true, we just run the code under it and we exit the condition completely.
All of these left part here does not run at all.
Only of the main if condition is false, then we check each and every ELIF.
And also if all of them are false, then as a default exit point, we run the aspart.
All right.
I think this summarize pretty nicely the basic part of conditions.
And it's a very, very useful and very crucial for you to understand this topic, because I can say
that a lot of the code that we are going to write further on is based on if conditions and also on loops
that which we our following topic.
So try to read this material again.
By the way, these this document is attached to the current video and Udemy in UDD toolbar.
And try just to watch that, just to read it again.
I think it would be very useful and in the next video will try to see more examples in the code in each
arm and see how can we understand this.
These flows better.
We will see both examples for simple if and for if examples in the code in the next video.
All right.
That's about it.
And next, after or after the examples, we will have a quick practice and then we'll go straight ahead
for the advanced part off if condition statements.
All right.
That's about it for this lecture.
I'll see you in the next one.
Thank you and bye bye.