WEBVTT 00:02.830 --> 00:03.370 Welcome. 00:04.550 --> 00:07.490 Now, I'm going to show you an example program about Sharriff statements. 00:09.630 --> 00:10.620 OK, let's get started. 00:13.270 --> 00:17.980 All right, now in this program, I'm going to get a number from the come on line, then I'm going to 00:17.980 --> 00:19.410 print it by doubling it. 00:19.420 --> 00:25.300 For example, when I read it like this, go around mean that go Cotan, it will display 20. 00:26.020 --> 00:26.380 All right. 00:26.530 --> 00:27.010 That's great. 00:27.040 --> 00:27.790 This program now. 00:29.520 --> 00:35.130 First, I'm going to use a simple statement to set the oyster marks to a variable right inside the if 00:35.130 --> 00:36.240 statement like this. 00:40.440 --> 00:44.790 Then I need to type the condition expression, so I'm going to type a semicolon here. 00:46.660 --> 00:49.450 The users should provide a number for the program, right? 00:49.690 --> 00:55.270 So now I'm going to check the length of the past arguments to see whether the user has provided an argument 00:55.270 --> 00:56.580 to the program or not. 00:58.350 --> 01:03.150 OK, if it's not too, then I'll display a message like this and give me a number. 01:04.540 --> 01:11.410 OK, let's try this now, let's call it in arguments first go around may not go, OK, as you can see, 01:11.420 --> 01:13.950 the Prince terror message kill it works. 01:14.620 --> 01:16.510 Now, let's create another branch here. 01:18.150 --> 01:21.960 I'm going to convert the past number using the TOI function like this. 01:24.710 --> 01:31.100 Here, I'm just short, declared Arabel in a simple statement, and I used a blank identifier to skip 01:31.100 --> 01:32.120 the converted value. 01:32.160 --> 01:34.430 For now, I'll change it soon, you'll see. 01:35.330 --> 01:37.850 OK, now I'm going to check for an error like this. 01:39.460 --> 01:43.600 So if the error is near that, it will mean that the conversion has failed. 01:45.200 --> 01:47.770 So let's display an message first. 01:47.840 --> 01:55.100 I'm going to type of formal text, cannot convert person to new line that I'm going to pass the command 01:55.100 --> 01:56.930 line argument a one. 01:57.960 --> 02:02.350 OK, now let's run this program using a name no value like this one. 02:03.150 --> 02:05.630 This way I can check whether the program works or not. 02:06.000 --> 02:08.230 As you can see, it cannot convert. 02:08.250 --> 02:08.620 Wow. 02:09.510 --> 02:11.970 Let me call it again without any arguments this time. 02:12.840 --> 02:15.030 So it also checks for that cool. 02:16.220 --> 02:19.940 Now, I'm going to change this blank identifier here to an variable. 02:21.010 --> 02:25.240 So the eight hour function will save the converted number into this web, OK? 02:26.230 --> 02:30.520 Do you know why I did it like so I mean, why I've typed a blank. 02:30.550 --> 02:33.570 I didn't fire first, then I change it to the variable. 02:35.390 --> 02:42.170 Since I didn't use the amber yet, so I wanted to run the program first, or it would give me valuable 02:42.170 --> 02:43.040 unused air. 02:43.650 --> 02:44.590 Now I'm going to use it. 02:44.630 --> 02:46.760 That's why I've changed it to the Amable now. 02:47.710 --> 02:53.770 OK, if the program reaches at this point, that means that everything is fine, there is a numeric 02:53.770 --> 02:55.600 argument, so let's print it now. 02:56.510 --> 03:03.080 I'm going to print it like this, I'm just going to type person test multiplied by two espersen the 03:03.230 --> 03:03.760 Nula. 03:04.980 --> 03:10.530 Then I'm going to pass the command line arguments, and that's the way I'm going to pass it, an expression 03:10.530 --> 03:16.740 that actually multiplies the cumulative number like this and multiply it by two. 03:17.520 --> 03:18.710 OK, let's run it now. 03:19.050 --> 03:20.530 Hopes there is another right. 03:21.060 --> 03:22.020 Let's check it out now. 03:23.200 --> 03:26.530 Says that and and variables are not defined here. 03:27.650 --> 03:32.780 It's because there are new variables inside the block, then only that block can use them. 03:33.650 --> 03:34.790 This is what happens here. 03:35.830 --> 03:41.500 This printer is out of the if statements block, so it can't access to the variables declared in the 03:41.500 --> 03:42.220 if statement. 03:43.240 --> 03:47.050 Now, let's move this printf inside and ask branch like this. 03:48.810 --> 03:54.480 Now, it's OK, as Branch can see, and access all the declared variables inside this, if statement 03:54.900 --> 03:57.990 is because the AZ branch belongs to this if statement. 03:59.020 --> 04:02.410 So this acid branch also belongs to the same incident. 04:03.410 --> 04:09.080 So that's why it can see the A1 variable here, you mean it was declared in previous if branch. 04:09.710 --> 04:15.890 Let me explain this to you by quickly adding comments on top of them so this if Branch can only see 04:15.890 --> 04:16.670 the Arab. 04:19.110 --> 04:27.870 And this as a branch can see the available and also an Arab abels and this as Branch can see all of 04:27.870 --> 04:30.720 the variables declared inside the whole if statement. 04:32.030 --> 04:37.010 So each branch can see only the variables of their own and from the previous branches. 04:38.940 --> 04:42.690 This is how scoping works in a statement with multiple blogs like this. 04:44.170 --> 04:48.690 So please bookmark this moment, you will get across to this in the upcoming lectures as well. 04:49.770 --> 04:54.230 Not that this time I haven't used in return statements to quit from the program, right. 04:55.560 --> 05:01.350 Since it only excuse the branches depending on the conditions, so I don't need to quit by typing a 05:01.360 --> 05:05.220 return or something else, for example, here, I don't need to type return. 05:05.670 --> 05:08.610 It's because there is nothing outside of this if statement. 05:09.120 --> 05:14.220 It is the last statement in the program, so it handles all the necessary conditions already. 05:15.030 --> 05:15.510 All right. 05:15.510 --> 05:16.760 Let's try this program now. 05:18.670 --> 05:21.070 I'm going to call it without any arguments like this. 05:22.600 --> 05:25.080 OK, it displays give me a number, cool. 05:25.270 --> 05:29.260 Now let's be a bad boy and let's give it a name number for now like this. 05:29.600 --> 05:32.410 As you can see, it says that I cannot convert that one. 05:32.680 --> 05:33.350 It's OK. 05:33.370 --> 05:34.000 It works. 05:35.200 --> 05:39.870 Now, let's be a good guy and give it a proper number like this for the two, all right. 05:39.880 --> 05:40.420 It works. 05:40.420 --> 05:45.240 It has multiply 42 by two and it has turned eighty four and is correct. 05:45.250 --> 05:50.350 Now, I'll help you understand how simple statements and blocks in a statement with multiple blocks 05:50.350 --> 05:50.800 works. 05:51.640 --> 05:55.750 So in summary, declared names in a block are only available to that block. 05:55.990 --> 06:01.450 However, they are also available to the following clauses or branches if they are declared using a 06:01.450 --> 06:02.380 simple statement. 06:06.320 --> 06:11.390 All right, congrats now you know how the short statement works in the next lecture, I'm going to show 06:11.390 --> 06:12.780 you one more example program. 06:12.950 --> 06:13.490 See you there.