WEBVTT 00:07.120 --> 00:07.570 Welcome. 00:08.020 --> 00:11.020 Now it's time to learn about the full range, Klaus. 00:12.180 --> 00:18.210 By the way, for change clubs isn't used only for looping or slices, it can also be used to loop over 00:18.210 --> 00:21.550 strings maps on channels to learn about those afterwards. 00:22.750 --> 00:25.020 For now, I'm going to focus on slices. 00:26.600 --> 00:27.560 OK, let's get started. 00:31.460 --> 00:37.550 This is the previous quote from the last lecture lesson factor, this got into a full range of then 00:37.550 --> 00:39.330 I'll talk about how it works in detail. 00:39.360 --> 00:43.220 OK, first I'm going to type the usual for keyword here. 00:43.760 --> 00:47.450 Then I'm going to short declare two variables and we. 00:50.160 --> 00:54.150 I hear means index and V means value. 00:55.130 --> 00:58.740 Then I'm going to type range, you're seeing it for the first time. 00:59.240 --> 01:02.530 Now I'm going to type the name of the slicer, which is Stoddart's. 01:07.510 --> 01:09.720 And that's it, this is the full range look. 01:10.560 --> 01:15.220 Oh, by the way, go warns me that I didn't use the inexorable I right. 01:16.030 --> 01:18.310 Let's change it to a blank identifier. 01:20.990 --> 01:23.320 As you can see, you can omit one of the variables. 01:23.780 --> 01:26.060 Now let's run it to see what it prints out. 01:27.640 --> 01:28.990 Hi, hey, hello. 01:29.910 --> 01:33.370 It works, however, it has printed the parts to the program. 01:34.050 --> 01:35.250 I don't want it to do so. 01:35.490 --> 01:36.770 So how can I keep it? 01:38.180 --> 01:43.550 I can check whether the index is zero, then I can let the followup continue, that will fix it. 01:43.760 --> 01:44.360 Let me show you. 01:45.480 --> 01:47.610 Let's bring back these indexable here. 01:48.980 --> 01:56.960 Now, this type, if the airable equals to zero, then let it keep looping by typing continue, right. 01:56.990 --> 01:57.730 Let's try it again. 02:01.390 --> 02:05.050 As you can see, it didn't print out the patina, so it works. 02:06.060 --> 02:10.140 Actually, there is a better but a slightly more advanced way to do this. 02:10.470 --> 02:14.820 Let me show you now I'm going to type a expression here like this. 02:16.150 --> 02:21.280 This will transform this slice and it will create a new slice of the new slice. 02:21.310 --> 02:27.190 We'll start from the second element, so it will basically keep the first item inside the slice. 02:28.200 --> 02:34.170 This I don't need to use the indexable anymore, I can change it back to a blank identifier like this. 02:35.570 --> 02:36.520 Now, let's run Ziggy. 02:38.060 --> 02:41.080 Could it didn't print out the part and it skipped it. 02:41.410 --> 02:45.030 As you can see, the expressions are very powerful things. 02:45.080 --> 02:48.110 I'll talk more about in the this section Dontari. 02:50.330 --> 02:54.010 All right, let's also change this program from the previous lecture as well. 02:55.200 --> 02:58.380 Let's duplicate this for loopier and less comment about. 02:59.760 --> 03:01.590 Now, let's remove these parts. 03:05.840 --> 03:12.370 And let's change them to our full range like this now, it does range over the verse slice here. 03:13.040 --> 03:17.330 I also need to change this verse just to we like this. 03:18.630 --> 03:23.100 Greenglass already puts it into the wee variable, so we don't need it here. 03:23.940 --> 03:25.360 All right, limerence up. 03:26.560 --> 03:32.860 As you can see, it brings out the words with their index, so these range here isn't different from 03:32.860 --> 03:35.500 this for loop in terms of functionality. 03:36.800 --> 03:38.770 However, compare these two. 03:38.800 --> 03:39.850 Which one is simpler? 03:40.700 --> 03:46.010 I think that range is very much simpler than the previous four Lupa, but I do think. 03:47.620 --> 03:50.050 OK, by the way, these variables can be reused. 03:50.440 --> 03:51.040 Let me show you. 03:52.120 --> 03:56.380 If I declare these variables out of the loop, they will look like this. 03:57.650 --> 04:01.970 Then instead of using the short declaration, I can use an assignment here like this. 04:03.940 --> 04:07.430 This way, the range glass will use these variables instead. 04:08.050 --> 04:09.520 So what the benefit of this? 04:11.500 --> 04:16.390 For example, you can continue to use them after the loop and the range class will keep them set up 04:16.540 --> 04:17.650 to their last value. 04:20.060 --> 04:21.950 Let me print them here right after the. 04:25.190 --> 04:29.660 That's valuable and we person to person to. 04:30.730 --> 04:33.610 Are we OK, let's turn it. 04:35.340 --> 04:39.700 As you can see, go prince, the lost values of the index and the value variable. 04:40.020 --> 04:43.830 So if you need to reduce those variables, you can do it like this. 04:45.310 --> 04:48.930 All right, now let's take a look at how far orange class works in detail. 04:55.130 --> 05:01.540 This highlighted part is called the range class, as you can see, it takes a slice and it returns to 05:01.550 --> 05:06.860 values from it one by one, and it updates stamp on each step of the loop. 05:07.750 --> 05:08.430 Let's continue. 05:10.260 --> 05:13.570 This part is totally the same with an ordinary four statement. 05:13.800 --> 05:15.260 Nothing interesting to see here. 05:15.450 --> 05:16.410 So let's continue. 05:18.160 --> 05:19.000 This is the next. 05:19.630 --> 05:25.810 It starts from zero and it will keep increasing automatically until the loop ends and the loop ends 05:25.810 --> 05:29.660 only after it loops over all the items inside the and slice. 05:31.020 --> 05:35.910 If you don't need the next variable, you can skip it by using our old friends blank identifier. 05:37.110 --> 05:41.360 You just need to replace the indexable blank, identify, that's it. 05:45.370 --> 05:53.830 This one here is the valuable, like the next Raible, the valuable is also optional on each step range, 05:53.830 --> 05:56.590 Clough's will assign the next value to this variable. 05:56.860 --> 05:59.260 It looks like this here. 05:59.290 --> 06:03.400 We get assigned to value from the first slice by using an index. 06:03.550 --> 06:08.250 However, this logic happens behind the scenes, so you don't even need to know about it. 06:10.780 --> 06:17.440 If you only need the next variable, the blank identifier can be used in place of it you so it will 06:17.590 --> 06:22.120 keep the values, actually you don't even need to use the blank identifier. 06:22.210 --> 06:23.950 Go has a better syntax for this. 06:24.280 --> 06:29.040 If what you need is only the index values, then you can remove the value variable entirely. 06:29.800 --> 06:32.080 The syntax is more concise, isn't it? 06:32.710 --> 06:37.630 I know there are a lot of developers out there still don't know about this syntax and they are still 06:37.630 --> 06:38.950 using the previous syntax. 06:39.760 --> 06:40.810 So bookmark this. 06:40.840 --> 06:42.130 You're going to need this, right? 06:42.550 --> 06:43.210 Let's continue. 06:45.290 --> 06:50.600 Obviously, this is the rescuers, it returns the next index and the value from the human expression 06:50.750 --> 06:55.370 for each items inside the slice, behind the scenes, it looks like this. 06:56.660 --> 07:02.390 Here, it assigns an index value to an index variable, and it also assigns the next value from the 07:02.390 --> 07:03.260 word slice. 07:05.360 --> 07:12.110 This part is the range expression, this expression can be anything that returns an array or a slice 07:12.110 --> 07:13.150 or a skin cancer. 07:13.850 --> 07:19.490 The interesting thing here is that you can range your fingers up because a string is actually a read-only 07:19.490 --> 07:20.220 bisley's. 07:20.240 --> 07:21.470 We'll talk about it later. 07:22.280 --> 07:22.730 All right. 07:22.880 --> 07:23.700 That's all for now. 07:24.200 --> 07:25.550 See, in the next picture, I.