Hello and welcome.
In this lecture we are going to perform some exercises on a race so that we can get more acquainted
with what an array is.
So the first exercise here we're going to define an array called fruits that will hold the names all
five fruits.
So it doesn't matter any fruit just any names or five fruits will do.
So what I'm gonna do I'm just going to comment out these lines of code here
OK and then I will define or we declare a new set of arrays.
When you are declared If you're declaring an array and initializing in it at the same time you don't
necessarily have to use the new operator.
Notice we use the new operator here because we didn't give it the values when we declared the arrays.
We first for declared it there and then we assign the values here.
But if you're declaring and assigning a value at the same time you can skip using the new operator.
So when you create in an array you first of four have to identify the data type because fruits names
are strings which means the attacks.
So the data type is going to be a string followed by square brackets followed by the name.
I want to call the variable.
It's going to be called fruits
K so because I'm not using the new operator I'm initializing the variable straightaway by assigning
it a value so to to assign a value we have to place it in curly braces.
Remember the assignment is to create a variable called fruits that will have the names of five fruits.
Make sure that you enclose the names with it with quotes because they say text.
So my first fruit will be an apple
I say apples.
Then you separate each of the elements in the array with a comma.
So my second one will be will be grapes
next will be Kiwi
my next will be say oranges
and the final one would be berries.
You don't need to put a comma with a large valley.
So this was the task to create an array called fruits that will have the names of five fruits.
All right.
So if I wanted to access say kiwi for example what I will do I'll come here and write Consul.
The right line
No not passing the name of my variable fruits
because an array 0 base.
I want to access Kiwi so Kiwi will be zero.
This apple will be 0.
Want to pass in to in that value.
Paul semicolon there.
And then do a console
the red line.
So so that the text can stay on the screen.
So if I execute this code here I will expect Kiwi to be displayed on the screen so click start to execute.
Just give it a few minutes for the code to run.
As you can see it is now displayed Kiwi on the screen all right on the exit that so if I wanted to display
the elements in the array I just come here.
Console the right line and type in the name of the array.
Dot land use the land property so far execute that it should give me should display five so click start
to run the code as you can see it is displayed five because there are five elements in the array.
So whenever you are declaring an array if this if the data type is a string which means text you must
enclose the elements in the array in quotes as I've done here.
So the examples I've done here you can use the same example to follow stuff but when you create in array
just bear in mind the data type.
So if you're going to create an array that was two numbers you declare integer if you're going to store
text you declare use the data type will be string.
OK so if you're going to store values are going to be true or false then the data type will be a ball
bowled means boolean which is true or false.
I said thank you so much for your time.
Bye for now.