Malcolm in his lecture, I'm going to show you how to loop over slices.
All right, let's get.
Do you remember that Arkes is just a slice of strings?
Let's take a look at this in the ED.
First, let's type of follow up.
To keep the program's name, I'm going to initialize it to one.
All right, now, this type of condition like this, I less than learn is that ARC's.
Don Incremented, OK.
As you know, is that ARC's gets the length of the slice, right?
So this will loop for each element inside the slice, it will loop onto the airable becomes less than
the number of elements inside the slice.
OK, now let me print the current element.
Pretty stiff person to new line.
I said, Arkes, I hear notice that I'm getting the element by using a variable instead of a number,
right.
Let me show you let me comment about this.
Called for now, then.
Let's copy this part here.
Then let's type it three times as an example like this.
A novelist changed, I'm able here to a number like this.
OK, now I'm going to run it with three arguments.
Hi.
Hello.
Hey.
As you can see, it prints each argument.
Let's get back.
Now, let's create a variable like this and use it instead as an index expression, it starts from one
for the next item.
Let's increase this very well and let's use it as an index expression.
They do the same for the last item as well.
OK, limerence again.
As you can see, it's prints the same output, right?
So using a number or a variable doesn't matter.
Novelist Lity Scott.
And uncommented the loop.
OK, let's try this again.
As you can see, the output is still the same.
Congress now you learned how to bring the slice.
Now, let's take a look at how to do the same thing for another sliceable that I'm going to create in
a minute.
Now, I'm going to call the fields function from the Springs package.
You know, is the result of the field's function to the words were able, right?
As you can see, fields function takes a string value and returns a slice of strings.
This is the same type of slice like the oyster arc slice that, you know, it will split the string
into its words and then it will return them as a slice.
OK, this allows me to saving the return slice to the words variable.
All right, now let's loop over the sliceable like this.
Here are initialize the variable to zero, because I want to loop over all the items of the word slice.
OK, now let's print it.
Now I'm going to use a formating verb with a minus sign in front of it is minus one here means that
hey, let's print these left aligned is just for pretty printing it.
And since the jury starts from zero here.
I have added one to it.
I'm going to print it like one, two, three, and so not like zero one, two.
OK.
Unless the I'm going to use an index expression to get an item from the word slice using the variable.
All right, limerence.
It prints the items inside the slice by word with their positions inside the sentence.
So if you compare these indexes to the birds inside this ring, you'll see that they match.
So, for example, here, a prince jumps right here.
Let's take a look at the terror threat inside the string.
Here the jobsworth is actually the third word inside this Trink, right?
Let me show you the words visual again.
Here it is.
These vertical lines are the spaces inside these three, right?
So swing state fields function split's this drink by looking at these space characters, then it becomes
like this.
Here, each one becomes a string value and each one is a part of the new slice that is returned from
the strings fields function, and also each one is actually an unnamed rebel, as I said previously.
So you can only access to them by using an index expression.
All right, in the next picture, I'm going to show you a much easier way to loop over strings.
See you there by.