Welcome.
Now it's time to learn about the full range, Klaus.
By the way, for change clubs isn't used only for looping or slices, it can also be used to loop over
strings maps on channels to learn about those afterwards.
For now, I'm going to focus on slices.
OK, let's get started.
This is the previous quote from the last lecture lesson factor, this got into a full range of then
I'll talk about how it works in detail.
OK, first I'm going to type the usual for keyword here.
Then I'm going to short declare two variables and we.
I hear means index and V means value.
Then I'm going to type range, you're seeing it for the first time.
Now I'm going to type the name of the slicer, which is Stoddart's.
And that's it, this is the full range look.
Oh, by the way, go warns me that I didn't use the inexorable I right.
Let's change it to a blank identifier.
As you can see, you can omit one of the variables.
Now let's run it to see what it prints out.
Hi, hey, hello.
It works, however, it has printed the parts to the program.
I don't want it to do so.
So how can I keep it?
I can check whether the index is zero, then I can let the followup continue, that will fix it.
Let me show you.
Let's bring back these indexable here.
Now, this type, if the airable equals to zero, then let it keep looping by typing continue, right.
Let's try it again.
As you can see, it didn't print out the patina, so it works.
Actually, there is a better but a slightly more advanced way to do this.
Let me show you now I'm going to type a expression here like this.
This will transform this slice and it will create a new slice of the new slice.
We'll start from the second element, so it will basically keep the first item inside the slice.
This I don't need to use the indexable anymore, I can change it back to a blank identifier like this.
Now, let's run Ziggy.
Could it didn't print out the part and it skipped it.
As you can see, the expressions are very powerful things.
I'll talk more about in the this section Dontari.
All right, let's also change this program from the previous lecture as well.
Let's duplicate this for loopier and less comment about.
Now, let's remove these parts.
And let's change them to our full range like this now, it does range over the verse slice here.
I also need to change this verse just to we like this.
Greenglass already puts it into the wee variable, so we don't need it here.
All right, limerence up.
As you can see, it brings out the words with their index, so these range here isn't different from
this for loop in terms of functionality.
However, compare these two.
Which one is simpler?
I think that range is very much simpler than the previous four Lupa, but I do think.
OK, by the way, these variables can be reused.
Let me show you.
If I declare these variables out of the loop, they will look like this.
Then instead of using the short declaration, I can use an assignment here like this.
This way, the range glass will use these variables instead.
So what the benefit of this?
For example, you can continue to use them after the loop and the range class will keep them set up
to their last value.
Let me print them here right after the.
That's valuable and we person to person to.
Are we OK, let's turn it.
As you can see, go prince, the lost values of the index and the value variable.
So if you need to reduce those variables, you can do it like this.
All right, now let's take a look at how far orange class works in detail.
This highlighted part is called the range class, as you can see, it takes a slice and it returns to
values from it one by one, and it updates stamp on each step of the loop.
Let's continue.
This part is totally the same with an ordinary four statement.
Nothing interesting to see here.
So let's continue.
This is the next.
It starts from zero and it will keep increasing automatically until the loop ends and the loop ends
only after it loops over all the items inside the and slice.
If you don't need the next variable, you can skip it by using our old friends blank identifier.
You just need to replace the indexable blank, identify, that's it.
This one here is the valuable, like the next Raible, the valuable is also optional on each step range,
Clough's will assign the next value to this variable.
It looks like this here.
We get assigned to value from the first slice by using an index.
However, this logic happens behind the scenes, so you don't even need to know about it.
If you only need the next variable, the blank identifier can be used in place of it you so it will
keep the values, actually you don't even need to use the blank identifier.
Go has a better syntax for this.
If what you need is only the index values, then you can remove the value variable entirely.
The syntax is more concise, isn't it?
I know there are a lot of developers out there still don't know about this syntax and they are still
using the previous syntax.
So bookmark this.
You're going to need this, right?
Let's continue.
Obviously, this is the rescuers, it returns the next index and the value from the human expression
for each items inside the slice, behind the scenes, it looks like this.
Here, it assigns an index value to an index variable, and it also assigns the next value from the
word slice.
This part is the range expression, this expression can be anything that returns an array or a slice
or a skin cancer.
The interesting thing here is that you can range your fingers up because a string is actually a read-only
bisley's.
We'll talk about it later.
All right.
That's all for now.
See, in the next picture, I.