Conditional programming or branching is something you do every day, every moment.
It's about evaluating conditions if the light is red.
Then I can cross.
If I'm hungry, I need to eat.
And if I'm late for work, then I will call my boss.
And the main tool is the if statement, which comes in different forms and colors.
But its basic function is to evaluate an expression and based on the result, choose which part of the
code to execute.
As usual, let's look at this example here.
So if I am Am is late here and true here true.
And after that we will.
If is late is true, then print.
I need I need to get.
I need to call my boss.
And this is possible.
The simplest example.
So when fed to if statement the is late acts as a conditional expression which is evaluated in a boolean
context.
And remember that is late here.
This is late variable here is boolean, not a string.
Not.
Value tuple or anything.
It is a boolean.
It's another primitive type.
Boolean.
You will learn about that in next lectures also.
So.
Uh, so Boolean also can Boolean has two values, either false or true.
So if the result of the evaluation is true, then we enter the body of the code immediately after the
if statement.
Notice that the print instruction is indented, which means that it belongs to scope defined by the
if here.
And that's because this is indentation here.
So if we run this code, as you can see, I need to call my boss.
If we make it is late.
False.
So we are not late for now.
And as you can see, we didn't evaluate anything.
So this code is didn't work or didn't need it to work here.
So depending on the result of evaluating the late is late expression, we can either enter block one
or block two, but not both.
So block one is executed when late evaluates to true while block two here is executed when the late
evaluates to false.
So try and assigning false and true to this is late too.
To see how the output of this code changes accordingly.
So in this example also introduced the else clause in which becomes very handy when we want to provide
an alternative set of instructions to be executed.
When an expression evaluates to false within an if class.
So the class is optional, as is evident by comparing preceding two examples.
And in with these examples we will do in next lecture.
So I'm waiting you in.
Next lecture.