WEBVTT 00:01.030 --> 00:01.600 Welcome. 00:02.110 --> 00:08.140 Now it's time to learn about the label statements, they allow you to jump to a label using a break, 00:08.140 --> 00:10.180 continue, or I go to statement. 00:11.300 --> 00:14.210 Let's start by exploring the labeled brake statement now. 00:18.420 --> 00:22.110 In this first example, you learn how to quit label loop. 00:22.140 --> 00:24.030 OK, let's suicide. 00:25.960 --> 00:27.790 Remember the bird finder program? 00:29.360 --> 00:34.880 In this program, the user queries the program using multiple words and the program searches for the 00:34.880 --> 00:36.770 matching words in its corpus. 00:37.280 --> 00:37.690 OK. 00:39.040 --> 00:43.900 Currently, it's only finds the unique parts and it skips to duplicates. 00:45.610 --> 00:51.460 This time, let's say that the system should only return the first words that it wants and then it will 00:51.550 --> 00:54.090 keep searching for more words altogether. 00:55.100 --> 01:00.680 So even though the user queries the program for multiple words, the system will only find the first 01:00.680 --> 01:03.630 query it worked once, then it will skip the rest. 01:03.670 --> 01:10.310 OK, for example, here it finds the again worked, but it doesn't care about the second part, the 01:10.310 --> 01:10.940 Antwoord. 01:11.980 --> 01:18.370 OK, so how can you add this feature to the program to do that, you need to use a labeled break segment, 01:18.850 --> 01:19.720 then use it. 01:19.720 --> 01:22.420 It will keep it from the whole loop when it finds out. 01:22.680 --> 01:23.410 Let's check it out. 01:29.980 --> 01:31.030 Remember, this got. 01:32.650 --> 01:36.010 The program searches for the correct words in this corpus. 01:36.950 --> 01:42.950 Right, and since that feels here creates a new slice by splitting the words inside the corpus. 01:43.890 --> 01:47.340 And lastly, this corridor will contain security guards. 01:49.500 --> 01:51.030 All right, let me run it first. 01:53.650 --> 01:59.650 With again and answers, as you can see, it finds the unique words inside the corpus. 02:01.310 --> 02:07.410 But now I'm going to only print the first matching words to do that, I need to terminate from the parent 02:07.460 --> 02:08.900 loop when it finds the words. 02:10.810 --> 02:15.930 But this brave statement here terminates from the inner loop, not from the parent, right? 02:16.720 --> 02:18.910 So how can I break from the parent loop? 02:20.350 --> 02:24.970 Of course, I just returned from this function, so the searching will end immediately. 02:25.510 --> 02:30.440 However, sometimes you can't do that and you might want to continue after the loop and so on. 02:31.270 --> 02:34.660 So how can I break from the parent loop without quitting from the program? 02:37.000 --> 02:39.850 To do that, I can use a label statement like this. 02:41.300 --> 02:42.590 I'm going to tie Puri's. 02:43.660 --> 02:48.550 So when I save the file, I've got warns me about that the break label isn't defined. 02:49.880 --> 02:50.860 Let's define it now. 02:51.800 --> 02:57.850 By the way, the position of a label is very important, so I want a break from the parent loop, right? 02:58.860 --> 03:01.380 Then I need to label the parent look like this. 03:02.290 --> 03:04.090 Now the warning has disappeared. 03:04.840 --> 03:11.560 Now these queries here is a label for this apparent loop, so you type a name for it and then you end 03:11.560 --> 03:13.180 it with a column and that's all. 03:13.990 --> 03:19.170 The real power of a label comes from the label statements, not from the label itself. 03:21.350 --> 03:27.000 Here Vandebroek statement is executed, it will break from the parent loop, not from the Knesset loop 03:27.080 --> 03:27.440 anymore. 03:28.190 --> 03:31.750 This is the difference of a label to make statements from a regular break. 03:32.510 --> 03:35.360 It allows you break from any label. 03:36.750 --> 03:37.980 OK, that's right. 03:39.170 --> 03:43.460 As you can see, as soon as it finds the again, it stops searching, right. 03:44.450 --> 03:49.640 This is because the label to break has terminated the loop after it has formed the search. 03:50.490 --> 03:51.140 Let me show you. 03:52.040 --> 03:59.900 Here is label kuris only labels, the first loopier, the parent, the one labeled Break Rense, it 03:59.900 --> 04:04.450 breaks from the first or the parent loop instead of the innermost or the nested loop. 04:05.510 --> 04:11.300 As you know, if the brake statement hasn't been labeled, then it will exit from the nested loop instead 04:11.810 --> 04:14.690 and the search for the other queries could continue. 04:15.710 --> 04:16.940 All right, let's get back. 04:21.190 --> 04:24.940 Let's move the kuris label into the inner loop to see what happens. 04:26.080 --> 04:30.820 Now, the curious label labels the nested loop instead of the parent loop, right? 04:31.920 --> 04:32.780 OK, let's try it. 04:34.090 --> 04:38.020 As you can see now with Prince, all the words instead of the first words. 04:39.210 --> 04:46.140 But here, using a labels break isn't necessary, let me comment off this label and just use an unlabeled 04:46.140 --> 04:47.340 break here like this. 04:48.970 --> 04:49.750 That's right again. 04:50.800 --> 04:52.850 As you can see, the result is the same. 04:53.770 --> 04:57.530 This is because the brake statement already breaks from the inner loop. 04:57.730 --> 04:59.430 So a label isn't necessary. 04:59.440 --> 05:01.510 Here, let me store it. 05:01.990 --> 05:02.470 All right. 05:03.370 --> 05:07.650 Here is label is only meaningful when I label the parent loop. 05:08.440 --> 05:12.430 So when it runs, it quits from the parent loop instead of the nested loop. 05:13.400 --> 05:18.920 By the way, if you don't use a label, Google will warn you because God doesn't let you declare on 05:19.270 --> 05:19.850 labels. 05:20.570 --> 05:22.700 It's like the unused variable error. 05:24.250 --> 05:26.560 For example, let me remove this label here. 05:29.320 --> 05:33.760 As you can see, NALGO says that you have defined the label, but you didn't use it. 05:35.270 --> 05:37.470 Let me do this, all right. 05:37.960 --> 05:42.380 Another rule is that labels do not conflict with the other names they you. 05:43.850 --> 05:46.190 Let's declare a variable name queries here. 05:49.820 --> 05:55.670 As you can see, there isn't a warning, right, because discovery is variable and the label are different 05:55.670 --> 06:01.970 things, even though they have the same names as, you know, normally you can't declare the same name 06:01.970 --> 06:03.310 inside the same block. 06:03.320 --> 06:03.770 Right. 06:04.310 --> 06:09.890 So this means that the labels do not share the same block with the other names like variables, constants 06:09.890 --> 06:10.430 and so on. 06:11.740 --> 06:18.310 But the labels still do have a scope, but it's not a block skop, their scope is actually the whole 06:18.310 --> 06:24.310 body of the function that they've been defining, which is a different scope from a block scope. 06:25.090 --> 06:27.520 That's why Go allows the same names. 06:28.680 --> 06:34.050 As you'll see in the go to statement, that unlike wearables and other names, labels can be defined 06:34.050 --> 06:35.710 even after they've been used. 06:36.150 --> 06:40.680 That's because they belong to the whole body of a function, not just to a block. 06:43.600 --> 06:47.710 Now, let's quickly take a look at how the labeled continua statement works as a. 06:52.630 --> 06:56.890 Now I'm going to show you the labeled continuous statement using the same word finder program. 07:02.470 --> 07:05.500 All those business people, now the requirements are changed. 07:06.220 --> 07:11.180 Now, the system should only bring unique words instead of finding the first match, the words. 07:11.890 --> 07:17.860 So when the user Currys for the again and the Antwerp's, it will print out again and the Antwerp's 07:17.860 --> 07:19.390 once, just like before. 07:20.540 --> 07:22.230 They changed their cameras again. 07:22.250 --> 07:23.150 Sorry about that. 07:23.660 --> 07:27.770 OK, let's take a look at how to do that using a labeled continuous statement. 07:28.850 --> 07:30.410 Let me open the previous program again. 07:31.910 --> 07:36.260 Now, here, instead of the brake statement, I'm going to change it into a continuous statement. 07:36.440 --> 07:36.770 OK. 07:39.080 --> 07:45.020 Here now, this is a labeled continua statement, so it finds the corporate word, it will keep the 07:45.020 --> 07:49.010 current type of dependent and it it'll make it continue from where it left off. 07:49.670 --> 07:52.140 It acts like a usual continuous statement. 07:52.160 --> 07:55.940 The only difference is that this time you can choose where it should continue. 07:57.480 --> 07:58.860 Let me show you how it works. 08:01.880 --> 08:04.280 As you can see, it's only Prince the unique words. 08:05.380 --> 08:09.130 Let me show you how it behaves when I make it an unlabelled continue. 08:13.290 --> 08:14.060 Let's run it now. 08:14.910 --> 08:17.550 As you can see, it prints out the duplicate for now. 08:18.450 --> 08:22.830 Now this continuous statement continues the nested loop instead of the loop. 08:23.880 --> 08:30.090 So when it finds the words, it just continues for the next step of the nested loop by using your labeled 08:30.090 --> 08:30.670 continuum. 08:30.810 --> 08:35.070 I could make it continue the parents loops loop instead of this inner loop. 08:37.120 --> 08:39.320 Let me undo this, OK? 08:39.820 --> 08:41.230 Let's take a look at Antwerp's. 08:43.340 --> 08:49.110 You're this scariest label on the labels, the first loopier, not the NSA. 08:49.610 --> 08:54.810 So here the NSA uses a label to continue Randee continue runs. 08:54.860 --> 08:58.220 It will continue from the parent loop instead of the nest of the. 08:59.710 --> 09:01.070 All right, that's all for now. 09:01.270 --> 09:04.570 This was how a labeled break and labels continue statements. 09:05.270 --> 09:06.610 OK, thank you for watching. 09:06.640 --> 09:07.600 See in the next picture. 09:07.660 --> 09:08.020 Bye bye.