Hi, this is command Reza. And in this video we are going to discuss flow controls in Python. I hope this given enjoyed and like it and you will learn a lot about this go controls and Python. Why I'm starting from very basic is generally if the foundations are strong, there is a strong possibility of very big building that could be developed. And therefore I've started from initially from data structure now moving forward towards Python flow controls, and let me know in through your comments feedback about this. So let's continue this flow controls in Python is there are like includes if else statement by loop, break and continue and Python pass.
In this video, we are going to discuss about FL statement There are four cases in if flow control in Python. The first one is only if the second one is if else. The third one is if Elif, and the fourth one is if sorry, the third one is if Elif else, and the fourth one is nested. Before starting this, let's discuss the flow of code in the form of diagram. an if statement in Python, Python engine tests the expression provided by the developer. And if it turns out to be true, it runs the body of a health.
If it is false, it exists the body of it. How does the Python engine recognizes that this part of the code is part of the if statement and not outside if statement? The Python engine does this by the indentation provided By the developer. So you can see here after if statement, there is a condition to be tested. And after that if the condition turns out to be true, it runs this block of code. And Python recognizes that this part of our code is inside the if statement by this indentation.
Let's run this and see what happens. I'm going to comment out this part of the code. I hit Control Enter. Here it is asking for me a number Iran, negative six is tested, what happens nothing happens. So the Python code enters and test this statement turns out to be false. So it does nothing because nothing is given by the developer.
However, if I give a positive six number Okay, it gives It prints out the positive numbers statement. So this is quite simple. The next part is let's see its diagram. The first statement is very simple in case of false. Earlier, the code used to exit If, however, in this case it exists the F F, but there is another block of code inside else that needs to be run when when the condition turns out to be false. And again, let's see it in the form.
For example, here now if the number is greater than zero, it is going to print positive number or else the number is going to be zero or less than zero. So it turns out, it is going to give the statement of negative number let's check negative six so it gives negative numbers Yes, it was not doing anything. The third part is, let's see the diagram if Elif and else now it has three different like three parallel structure. If the true if the condition turns out to be true, it runs the body of a if it is false, it runs a body of lF, after checking the test expression in other and if it turns out to be false in lf it runs the body of L statements. So it's kind of a nested F. Let's see this. Here.
It checks whether the number is greater than zero if it is it is going to run this part of the code. If it is not, it is going to check out and in the condition that is other and see if the num is equal to zero. If it is true, it prints zero. Otherwise, it goes to as intensely negative numbers. Let's run this I put zero and it gives zero. And the similar thing is using nested, nested if means, one inside another, so it could be like multiple eggs within a single F. However, it becomes very complicated to understand, though, generally, lF is used.
See this number is greater than zero, the code enters this part of the code. It checks if the number is equal to 0.0. Else if the number is not equal to zero, it is definitely going to be a positive number. And if there is nothing, not the case number is less than zero. Then it will directly jump to as fat in the negative number. Let's check out negative I have positive light.
So it's a positive number. If it is 00 and if it is negative nine, it's a negative number. See very simple. I hope you liked it. And now you have a better understanding of control flow is using F, Elif, and else and mastered if you want to continue learning like it, give feedback. Let me know if you need videos or any on any special topic within Python.
Thank you