1 00:00:00,750 --> 00:00:01,650 Hello and welcome. 2 00:00:01,650 --> 00:00:10,860 In this lecture we are going to perform some exercises on a race so that we can get more acquainted 3 00:00:10,890 --> 00:00:12,860 with what an array is. 4 00:00:12,960 --> 00:00:23,640 So the first exercise here we're going to define an array called fruits that will hold the names all 5 00:00:23,700 --> 00:00:25,460 five fruits. 6 00:00:25,530 --> 00:00:29,760 So it doesn't matter any fruit just any names or five fruits will do. 7 00:00:31,710 --> 00:00:37,460 So what I'm gonna do I'm just going to comment out these lines of code here 8 00:00:45,550 --> 00:00:52,190 OK and then I will define or we declare a new set of arrays. 9 00:00:52,560 --> 00:00:59,280 When you are declared If you're declaring an array and initializing in it at the same time you don't 10 00:00:59,280 --> 00:01:02,960 necessarily have to use the new operator. 11 00:01:03,540 --> 00:01:10,740 Notice we use the new operator here because we didn't give it the values when we declared the arrays. 12 00:01:11,040 --> 00:01:15,630 We first for declared it there and then we assign the values here. 13 00:01:15,670 --> 00:01:23,580 But if you're declaring and assigning a value at the same time you can skip using the new operator. 14 00:01:23,610 --> 00:01:31,170 So when you create in an array you first of four have to identify the data type because fruits names 15 00:01:31,260 --> 00:01:33,870 are strings which means the attacks. 16 00:01:33,930 --> 00:01:45,710 So the data type is going to be a string followed by square brackets followed by the name. 17 00:01:45,720 --> 00:01:47,940 I want to call the variable. 18 00:01:48,060 --> 00:01:49,410 It's going to be called fruits 19 00:01:53,940 --> 00:02:01,500 K so because I'm not using the new operator I'm initializing the variable straightaway by assigning 20 00:02:01,500 --> 00:02:10,560 it a value so to to assign a value we have to place it in curly braces. 21 00:02:10,590 --> 00:02:22,630 Remember the assignment is to create a variable called fruits that will have the names of five fruits. 22 00:02:22,710 --> 00:02:31,230 Make sure that you enclose the names with it with quotes because they say text. 23 00:02:31,230 --> 00:02:33,180 So my first fruit will be an apple 24 00:02:35,990 --> 00:02:38,480 I say apples. 25 00:02:38,480 --> 00:02:46,130 Then you separate each of the elements in the array with a comma. 26 00:02:46,130 --> 00:02:48,640 So my second one will be will be grapes 27 00:02:54,450 --> 00:02:57,450 next will be Kiwi 28 00:03:02,310 --> 00:03:07,080 my next will be say oranges 29 00:03:13,280 --> 00:03:18,710 and the final one would be berries. 30 00:03:18,820 --> 00:03:24,720 You don't need to put a comma with a large valley. 31 00:03:25,000 --> 00:03:33,890 So this was the task to create an array called fruits that will have the names of five fruits. 32 00:03:34,670 --> 00:03:35,180 All right. 33 00:03:35,200 --> 00:03:51,730 So if I wanted to access say kiwi for example what I will do I'll come here and write Consul. 34 00:03:52,530 --> 00:03:53,510 The right line 35 00:03:56,680 --> 00:04:01,980 No not passing the name of my variable fruits 36 00:04:05,470 --> 00:04:08,670 because an array 0 base. 37 00:04:08,710 --> 00:04:11,590 I want to access Kiwi so Kiwi will be zero. 38 00:04:11,590 --> 00:04:13,220 This apple will be 0. 39 00:04:13,280 --> 00:04:18,340 Want to pass in to in that value. 40 00:04:18,970 --> 00:04:20,280 Paul semicolon there. 41 00:04:21,190 --> 00:04:22,750 And then do a console 42 00:04:27,770 --> 00:04:28,960 the red line. 43 00:04:28,980 --> 00:04:36,780 So so that the text can stay on the screen. 44 00:04:37,860 --> 00:04:46,770 So if I execute this code here I will expect Kiwi to be displayed on the screen so click start to execute. 45 00:04:46,770 --> 00:04:53,190 Just give it a few minutes for the code to run. 46 00:04:54,000 --> 00:05:05,050 As you can see it is now displayed Kiwi on the screen all right on the exit that so if I wanted to display 47 00:05:05,080 --> 00:05:08,380 the elements in the array I just come here. 48 00:05:08,590 --> 00:05:13,950 Console the right line and type in the name of the array. 49 00:05:14,550 --> 00:05:24,910 Dot land use the land property so far execute that it should give me should display five so click start 50 00:05:25,030 --> 00:05:33,470 to run the code as you can see it is displayed five because there are five elements in the array. 51 00:05:33,790 --> 00:05:41,440 So whenever you are declaring an array if this if the data type is a string which means text you must 52 00:05:41,530 --> 00:05:48,730 enclose the elements in the array in quotes as I've done here. 53 00:05:49,730 --> 00:05:57,070 So the examples I've done here you can use the same example to follow stuff but when you create in array 54 00:05:57,080 --> 00:05:58,840 just bear in mind the data type. 55 00:05:59,210 --> 00:06:05,210 So if you're going to create an array that was two numbers you declare integer if you're going to store 56 00:06:05,510 --> 00:06:10,590 text you declare use the data type will be string. 57 00:06:11,280 --> 00:06:17,030 OK so if you're going to store values are going to be true or false then the data type will be a ball 58 00:06:17,540 --> 00:06:22,460 bowled means boolean which is true or false. 59 00:06:22,460 --> 00:06:24,680 I said thank you so much for your time. 60 00:06:24,680 --> 00:06:25,310 Bye for now.