WEBVTT

00:00.890 --> 00:07.670
Conditional programming or branching is something you do every day, every moment.

00:07.700 --> 00:11.930
It's about evaluating conditions if the light is red.

00:13.360 --> 00:14.650
Then I can cross.

00:16.280 --> 00:18.170
If I'm hungry, I need to eat.

00:18.940 --> 00:23.940
And if I'm late for work, then I will call my boss.

00:23.950 --> 00:30.790
And the main tool is the if statement, which comes in different forms and colors.

00:30.790 --> 00:38.440
But its basic function is to evaluate an expression and based on the result, choose which part of the

00:38.440 --> 00:39.670
code to execute.

00:39.700 --> 00:43.860
As usual, let's look at this example here.

00:43.870 --> 00:52.630
So if I am Am is late here and true here true.

00:52.630 --> 00:54.070
And after that we will.

00:54.070 --> 00:58.510
If is late is true, then print.

00:58.690 --> 01:03.070
I need I need to get.

01:03.430 --> 01:07.720
I need to call my boss.

01:09.850 --> 01:11.110
And this is possible.

01:11.110 --> 01:12.610
The simplest example.

01:12.610 --> 01:22.150
So when fed to if statement the is late acts as a conditional expression which is evaluated in a boolean

01:22.150 --> 01:22.690
context.

01:22.690 --> 01:25.090
And remember that is late here.

01:25.120 --> 01:31.180
This is late variable here is boolean, not a string.

01:31.180 --> 01:31.750
Not.

01:33.110 --> 01:35.240
Value tuple or anything.

01:35.240 --> 01:36.350
It is a boolean.

01:36.350 --> 01:38.150
It's another primitive type.

01:38.240 --> 01:39.380
Boolean.

01:39.740 --> 01:43.660
You will learn about that in next lectures also.

01:43.670 --> 01:44.510
So.

01:45.580 --> 01:51.460
Uh, so Boolean also can Boolean has two values, either false or true.

01:51.490 --> 01:58.210
So if the result of the evaluation is true, then we enter the body of the code immediately after the

01:58.210 --> 01:58.930
if statement.

01:58.960 --> 02:07.960
Notice that the print instruction is indented, which means that it belongs to scope defined by the

02:07.960 --> 02:08.980
if here.

02:08.980 --> 02:11.020
And that's because this is indentation here.

02:12.160 --> 02:17.560
So if we run this code, as you can see, I need to call my boss.

02:17.590 --> 02:19.450
If we make it is late.

02:19.450 --> 02:19.930
False.

02:19.930 --> 02:22.150
So we are not late for now.

02:22.150 --> 02:24.820
And as you can see, we didn't evaluate anything.

02:24.820 --> 02:29.410
So this code is didn't work or didn't need it to work here.

02:29.500 --> 02:37.390
So depending on the result of evaluating the late is late expression, we can either enter block one

02:37.390 --> 02:39.640
or block two, but not both.

02:39.640 --> 02:48.430
So block one is executed when late evaluates to true while block two here is executed when the late

02:48.430 --> 02:49.960
evaluates to false.

02:49.960 --> 02:54.850
So try and assigning false and true to this is late too.

02:55.360 --> 02:59.830
To see how the output of this code changes accordingly.

02:59.830 --> 03:08.260
So in this example also introduced the else clause in which becomes very handy when we want to provide

03:08.260 --> 03:11.380
an alternative set of instructions to be executed.

03:11.380 --> 03:15.320
When an expression evaluates to false within an if class.

03:15.320 --> 03:21.740
So the class is optional, as is evident by comparing preceding two examples.

03:21.740 --> 03:25.460
And in with these examples we will do in next lecture.

03:25.460 --> 03:26.210
So I'm waiting you in.

03:26.210 --> 03:26.750
Next lecture.
