WEBVTT 00:03.400 --> 00:05.080 Welcome, intellectual. 00:05.140 --> 00:09.500 I'm going to show you how fall through in a suit statement works first. 00:09.520 --> 00:12.360 I'm going to show you a code snippet without follow through. 00:12.520 --> 00:16.020 Then I'll refactor it into a version with false rule statements. 00:16.540 --> 00:17.590 OK, let's get started. 00:20.910 --> 00:25.240 Let's say that I want to create a program that will print the message depending on a number. 00:26.160 --> 00:26.850 Let me show you. 00:29.070 --> 00:31.230 Let's declare and travel like this. 00:34.900 --> 00:37.570 When the ivory bill is greater than 100. 00:38.600 --> 00:41.600 Then I'm going to print big positive number like this. 00:44.480 --> 00:51.110 Or if the airable is less than a hundred and if it's a positive number, then I'm going to print positive, 00:51.110 --> 00:51.500 no. 00:56.070 --> 01:02.730 To reach this case, it has to go through the Ebola case first, so here I know that the number is less 01:02.730 --> 01:07.560 than 100, right, because it already went through the Ebola case first. 01:08.500 --> 01:11.800 Otherwise, I'm going to use a default case and I'll just print No. 01:13.030 --> 01:20.470 Since it reaches this case, it means that the number is either equal to zero of its negative, for 01:20.620 --> 01:23.140 example, I don't care about the negative numbers. 01:23.180 --> 01:26.270 OK, OK, now let me execute this program. 01:27.220 --> 01:29.350 It just brings back positive number. 01:29.860 --> 01:32.950 It's because the airable is greater than 100. 01:34.140 --> 01:36.690 Let me run this inside the code editor Ezer. 01:46.740 --> 01:51.060 Here is the program, as you can see, it brings back positive No. 01:52.200 --> 01:56.430 OK, now let's change the number to something less than handon like this. 01:57.920 --> 01:58.940 OK, let's try to take a. 02:00.070 --> 02:01.960 No, DePrince, just positive, no. 02:04.220 --> 02:10.970 Is because it hits this case first eye is greater than handprint, so it yields false. 02:11.940 --> 02:15.280 Then it tries this next case greater than zero. 02:16.020 --> 02:17.280 This case yields true. 02:17.370 --> 02:18.780 So it runs this case. 02:19.560 --> 02:21.750 Novelis changed his number to zero. 02:22.760 --> 02:23.690 OK, let's run it again. 02:25.040 --> 02:30.500 This time, it just prints no, it's because it has tried all these cases. 02:31.540 --> 02:39.100 But all of them were false, so it gave up and just executed this default glass because there were no 02:39.100 --> 02:40.030 more options left. 02:41.680 --> 02:48.300 As you can see in this program, I need to repeat this positive number and number values, right? 02:49.670 --> 02:54.020 Actually, there's a better way I can use a follow through statement instead, I'm sure you. 03:00.000 --> 03:02.310 I removed the duplicate strings now. 03:03.940 --> 03:07.990 Now, I'm going to add a few full true statements at the end of each case, glossier. 03:09.080 --> 03:11.510 First, I'm going to add a full true statement here. 03:12.720 --> 03:14.460 Then I'm going to add another one here. 03:15.490 --> 03:22.270 You'll see why that I'm doing this in a minute is, by the way, keep in mind that full true statement 03:22.270 --> 03:25.620 should be the last statement inside a case, Claus's block. 03:25.840 --> 03:26.280 OK. 03:27.510 --> 03:29.910 OK, now on this program line by line. 03:31.090 --> 03:34.330 Here is a line pointer when it moves on a line. 03:34.540 --> 03:37.540 It means that deadline is going to be executed next. 03:38.760 --> 03:41.070 OK, first he tries this case condition. 03:42.740 --> 03:48.650 Since the airable is greater than 100, so it runs this case, it brings big. 03:50.280 --> 03:55.290 Now it's about to execute the fall truth statement, what will happen when it executes it? 03:56.240 --> 04:01.670 Let me tell you, this minute rounds to fall through statement, the program will direct the jump to 04:01.670 --> 04:03.020 the next casis block. 04:03.690 --> 04:10.070 So here it will jump to the left, empty that sprint without excluding the next case is condition. 04:11.110 --> 04:11.850 Let's check it out. 04:12.730 --> 04:18.130 As I said, it has jumped to the print and printed positive next to big. 04:19.440 --> 04:25.530 So the full truth is used, it won't care about the next cases, condition, expression, and it will 04:25.530 --> 04:27.090 directly execute its black. 04:28.030 --> 04:34.420 Here, Volterra is safe because I know that handwrote is a positive number, so I don't need to check 04:34.420 --> 04:38.460 the next casis condition, so I'll just let it fall through to it. 04:40.060 --> 04:45.250 Now it's on the next fall, true statement again, it's going to drag the full truth to the default 04:45.250 --> 04:47.500 chaos block as if it was never been there. 04:48.100 --> 04:49.720 So it has printed no. 04:50.930 --> 04:57.320 In the end, the output becomes a positive number without having to repeat the Sphinx. 04:58.380 --> 05:05.040 As you've seen, instead of the brake statements, go has full truth statements in other languages, 05:05.250 --> 05:07.020 there is no follow through statement. 05:07.890 --> 05:14.460 Instead, they go to the next class automatically, that's why they need a brake statement, for example, 05:14.460 --> 05:20.040 in JavaScript, in a switch statement, if you don't put a brake statements, it will execute the next 05:20.040 --> 05:21.360 class automatically. 05:22.230 --> 05:29.160 However, God doesn't need it because as I showed you before, go ask the brake statements to the end 05:29.160 --> 05:31.080 of the each case clause automatically. 05:32.020 --> 05:35.830 Let me show you this card in the codding Ed with different inputs. 05:41.560 --> 05:45.940 Let's run this as it is, it brings back positive number. 05:46.210 --> 05:50.410 All right, now let's change the number to 80, for example. 05:51.360 --> 05:52.170 That's right now. 05:53.540 --> 05:55.940 It brings positive number as expected. 05:57.830 --> 06:04.580 This is because this case condition was true, so Gore has executed it then it has followed through 06:04.790 --> 06:05.960 to the default clause. 06:06.980 --> 06:09.350 Now, let's change the number to zero. 06:10.190 --> 06:11.050 Let's run it now. 06:12.370 --> 06:13.840 It just prints no. 06:14.840 --> 06:20.360 This is because both cases were false, so it has only executed the default clause. 06:21.300 --> 06:23.550 Actually, this was just a demonstration. 06:23.580 --> 06:29.390 It doesn't mean that I would do this in a real life scenario, but it explains how awful through works. 06:30.060 --> 06:36.600 Actually, a fall true statement is rarely used, but sometimes it may become useful, as in here. 06:37.580 --> 06:38.900 All right, they're so. 06:40.970 --> 06:41.590 Congrats. 06:41.630 --> 06:47.630 Now you know how to use expressions within to each statement, and you also learned about the fall through 06:47.630 --> 06:48.200 a statement. 06:48.710 --> 06:51.710 Thank you for watching and see in the next lecture by my.