WEBVTT 00:01.320 --> 00:02.130 Welcome back. 00:02.670 --> 00:07.660 In his lecture, I'm going to talk about how to create and initialize areas at the same time. 00:08.250 --> 00:09.350 So let's get started. 00:11.410 --> 00:17.830 First, let's create the same rate that we have created in the last lecture, this court creates an 00:17.830 --> 00:21.700 array variable with four empty string values like this one. 00:22.480 --> 00:25.330 Now let's initialize all the elements of disarray. 00:26.080 --> 00:28.720 Let's assign Kavkaz Revanche to the first element. 00:29.560 --> 00:31.630 Stay golden to the second element. 00:32.590 --> 00:34.660 Everything shipped to the third element. 00:36.240 --> 00:40.470 And lastly, let's assign Cafcass second edition to the last element. 00:41.220 --> 00:43.500 All right, here's the question. 00:44.100 --> 00:48.330 Isn't it cumbersome to initialize the elements of an array like this one? 00:48.330 --> 00:54.480 By one, I mean, first you need to create the array variable and then you need to initialize its elements 00:54.480 --> 00:57.040 one by one using the assignment statements. 00:57.810 --> 00:59.580 Fortunately, there is a better way. 00:59.910 --> 01:00.920 Let's take a look at it. 01:03.460 --> 01:04.780 This is an area litoral. 01:05.910 --> 01:12.780 It creates a new era with the given elements at the same time, then I assigned the new era to the book's 01:12.780 --> 01:13.450 variable here. 01:13.860 --> 01:14.760 It's that simple. 01:15.600 --> 01:21.640 By the way, I don't need to use this normal declaration syntax, I can also use the short declaration. 01:21.660 --> 01:22.350 Let me show you. 01:23.620 --> 01:30.730 This is equal to the previous syntax, however, here, go figure out the book's variables type automatically. 01:31.270 --> 01:35.230 So the book's variables type becomes a string theory with four elements. 01:35.950 --> 01:40.450 So always use this syntax whenever you know about the initial elements. 01:40.480 --> 01:42.860 OK, let's take a look at this area. 01:42.910 --> 01:48.880 Literal syntax in detail, actually, a very literal one of the composite literals. 01:49.420 --> 01:51.000 So what's a composite literal? 01:51.400 --> 01:58.510 In summary, a composite literal creates a composite value like an array and a composite value is a 01:58.510 --> 02:00.400 container or other values. 02:00.880 --> 02:07.270 So here this composite array literally creates a new era value along with its elements. 02:07.600 --> 02:12.420 OK, so first you need to type the composite literals type here. 02:12.430 --> 02:15.400 Go creates new array with four swink elements. 02:15.940 --> 02:19.500 Then I'm initializing the elements of the new area in an element list. 02:20.350 --> 02:23.590 This highlighted part is the element list of the new array. 02:24.280 --> 02:26.790 It starts and ends with curly braces. 02:27.280 --> 02:30.610 However, please do not confuse this with a block. 02:31.090 --> 02:33.810 It's not a block and it doesn't create a new skop. 02:33.820 --> 02:41.590 OK, it just initializes the arrays elements and also notice that we need to separate the elements using 02:41.590 --> 02:42.160 commas. 02:42.610 --> 02:46.310 So each element in this list needs to end with a comma. 02:47.110 --> 02:54.060 You also need to type the last comma is in here because here I have type the elements in multiple lines. 02:54.850 --> 03:01.000 By the way, if I had typed the last element just before the ending culbreath, the last comma wouldn't 03:01.000 --> 03:01.690 be necessary. 03:02.140 --> 03:04.360 For example, here I don't need to type. 03:04.360 --> 03:09.760 The last comma is because here the culebras is next to the last element. 03:09.940 --> 03:10.350 Right? 03:11.230 --> 03:13.360 So you don't have to type the last comma here. 03:14.320 --> 03:20.890 And yet you can also type the composite literals on a single line like this, by the way, here, the 03:20.890 --> 03:23.110 length of this area is four, right? 03:23.890 --> 03:28.540 However, here I'm initializing only the first two elements of Desiré. 03:28.540 --> 03:28.740 Right. 03:29.500 --> 03:31.510 So where are the rest of the elements? 03:32.410 --> 03:33.680 Here's a question for you. 03:34.420 --> 03:37.240 So what would happen when I run this called? 03:38.060 --> 03:40.610 What the areas elements will look like. 03:45.480 --> 03:46.800 OK, let's find out. 03:47.890 --> 03:54.730 So these are literal initializes the first two elements, first dango, initializes the rest of the 03:54.730 --> 04:01.600 elements to their zero values, since this is a citrine, Kyra, so they become Amita's rings. 04:02.770 --> 04:10.930 This happens because the land is for remember, areas are fixed, composite values, unlike some other 04:10.930 --> 04:15.620 languages, go always initializes the elements to their zero values. 04:16.360 --> 04:19.530 This prevents a lot of potential bugs along the road. 04:20.300 --> 04:25.420 And by the way, there is also another useful syntax called the ellipsis operator. 04:26.020 --> 04:29.110 This is what it looks like, three consecutive. 04:29.120 --> 04:30.480 That's that's it. 04:31.390 --> 04:37.070 With this syntax, the number of elements determines the land of the array here. 04:37.090 --> 04:38.290 There are two elements. 04:38.680 --> 04:41.870 So the area is like automatically becomes two as well. 04:42.610 --> 04:45.220 And in the end, this array gets created. 04:46.090 --> 04:53.440 As you can see, there are no zero elements because with this syntax, the array becomes fully initialized. 04:54.680 --> 04:56.280 All right, that's all for now. 04:56.750 --> 04:58.340 Thank you for watching so far. 04:58.610 --> 05:03.480 In the next picture, we're going to refactor the hipster's bookstore to Literals. 05:03.860 --> 05:05.170 See you there by.