WEBVTT 00:02.270 --> 00:07.610 Welcome in his lecture, I'm going to talk about the labeled break statement again, but this time I'm 00:07.610 --> 00:10.070 going to use it to terminate from a switch statement. 00:10.100 --> 00:10.430 OK. 00:11.300 --> 00:15.070 It's a lot before you can use a break statement to terminate the switch statement. 00:16.430 --> 00:22.430 But a which statement is inside of a loop, will it terminate from the loop or from the switch is unclear. 00:22.520 --> 00:22.970 Right. 00:24.270 --> 00:29.110 So by using a label statement, you can Talgo which statement you actually want to terminate. 00:29.670 --> 00:30.220 All right. 00:30.360 --> 00:32.880 Without further ado, let's take a look at an example. 00:39.440 --> 00:44.840 You know, normally the user queries the word find that program and the matched words get printed, 00:44.930 --> 00:45.290 right. 00:46.010 --> 00:49.580 However, now the business people have changed the requirements again. 00:50.440 --> 00:53.470 Now they want a filter, they macharia. 00:54.780 --> 00:59.220 So when the user queries the system, the correct words will go through a filter. 00:59.700 --> 01:03.870 If one of the queries works is in the filter, then it won't be searched for. 01:04.080 --> 01:07.710 So the filter adverts won't appear in the search results. 01:07.790 --> 01:08.220 OK. 01:09.380 --> 01:16.760 Here, the user searches for the again and the Antwerp's, but the Antwoord is an unwanted part since 01:16.760 --> 01:22.490 it's in the filter so the program won't search for it, it will only search for the keywords. 01:23.090 --> 01:27.710 Now, let's take a look at how to add this new feature into the word finder program. 01:30.450 --> 01:32.100 I opened the previous program again. 01:32.730 --> 01:35.640 The customer has said that the filter will be static for now. 01:36.450 --> 01:40.500 So I think that I can filter the unwanted words using a switch statement. 01:41.440 --> 01:45.760 Now, I'm going to type a switch statement here to filter the query words like this. 01:47.580 --> 01:52.620 OK, now I'm going to typed unwanted words in a case closed like this case. 01:53.470 --> 01:56.560 And or the OK. 01:57.700 --> 02:03.700 So whenever the corporate world matches to the works in this case, close, this case clause will be 02:03.700 --> 02:04.180 excluded. 02:04.340 --> 02:04.680 OK. 02:05.590 --> 02:08.480 I've used a switch statement instead of a statement here. 02:08.740 --> 02:10.810 Do you wonder why I did so? 02:10.810 --> 02:13.880 Because I like the conciseness of switch statement. 02:14.140 --> 02:15.510 I think that's more readable. 02:16.210 --> 02:17.770 I showed you this before. 02:19.730 --> 02:25.040 Anyway, your inside, I'm going to break from it, let's see what happens when I do this. 02:25.440 --> 02:28.280 Let's query the program using an unwanted word now. 02:29.490 --> 02:36.810 Again, and lazy as you can see, it finds all the words I've typed, but it also finds at Princeton 02:36.810 --> 02:38.470 wants towards the Antwoord. 02:38.970 --> 02:41.970 That's because this break here breaks from the switch. 02:42.390 --> 02:45.220 Then it continues and executes these statements. 02:45.690 --> 02:51.750 So if nothing has changed here for now to fix this, I can add the labeled brake statement to Talgo 02:51.750 --> 02:54.130 that I don't want to break just from the switch. 02:54.300 --> 02:56.010 I also want a break from the NSA. 02:56.490 --> 02:58.230 OK, let's do that now. 02:59.730 --> 03:05.490 Now, I'm going to add another label just before the nested loop here, so these labels to nested loop 03:05.490 --> 03:06.720 with a search label now. 03:07.300 --> 03:13.320 Now, let's at this label next to the break here so that it will break out of the nested instead of 03:13.320 --> 03:13.830 the switch. 03:15.260 --> 03:18.200 Now, let's query the program using an unwanted word again. 03:19.330 --> 03:25.420 Cool, now it filters out the unwanted words and the searches and prints for the wanted word since that 03:25.420 --> 03:25.840 Dritz. 03:27.080 --> 03:31.100 Let me show you the difference between an unlabelled break with a label, one A. 03:32.970 --> 03:39.150 So when you use an unlabeled break inside a switch like this, it breaks out of the switch, then it 03:39.150 --> 03:43.010 continues executing the rest of the statements right after the switch statement. 03:43.920 --> 03:46.800 Is because God thinks that you want a break from the sewage. 03:48.330 --> 03:55.680 However, use a label to inside a switch breaks out of the loop, instead they'd continues executing 03:55.680 --> 03:57.990 the rest of the code after the next loop. 03:58.590 --> 03:59.160 All right. 03:59.580 --> 04:00.340 That's all for now. 04:00.630 --> 04:05.280 So in summary, you can use a labeled break to quit from the loop instead of a switch. 04:06.090 --> 04:07.410 OK, thank you for you. 04:07.650 --> 04:08.720 See in the next picture. 04:08.850 --> 04:09.220 Oh, I.