Valka now it's time to learn about the four range Klaus by the way for Ange Klaus isn't use only for
looping over slices.
It can also be used to loop over strings maps and channels to learn about those aftershocks.
For now I'm going to focus on slicers OK.
Ask Assata
does the previous card from The Last Lecture ness factor discard into off whole range.
Then I'll talk about how it works in detail.
First I'm going to type the usual for q or two year term and a short éclair to wearables and way
I here means index and V means value done wina type range.
You're seeing it for the first time.
Now I'm going to type the name of Sly's which is east of Arc's
and that's it.
This is the full range look.
Oh by the way go warns me that I didn't use the index or table I writes.
Let's change it to eyeblink identifier
as you can see.
You can omit one of two variables.
Now this no need to see what it preens out.
Hey hello it's works.
However it has printed the Pats to the program.
I don't want it to do so.
So how can I keep it.
I can't check whether the index is zero.
Then I can let the for loop continue.
That will fix it.
Let me show this bring back the index table here.
Now let's type if the Iredell equals to zero.
That little keep looping by typing continue.
Right that's right again
as you can see it didn't print out the pattern so it works.
Actually there is a better but a slight bit more of the man's way to do this.
I'm sure you're not going to type a slice expression here like this.
This will transform this slice and it will create the new slice of the new slice will start from the
second element.
So it will basically keep the first item inside.
Slice since I don't need to use the index table anymore I can change it back to a blank identifier like
this.
Now this one second Q..
It didn't print out the part and it skipped it as you can see slicing expressions are very powerful
tinks.
I'll talk more about Dom in the slices section.
Andre All right.
Let's also change this program from the previous lecture as let's duplicate this follow up here and
let's come and start.
Now this.
These parts
and lists change down to 4 range like this.
Now we do range over the first slice here.
I also need to change these verst J to.
We like this range class already puts it into the we variable.
So we don't need that here.
All right.
Limerence.
As you can see it prints out the words right there in Texas.
So this range here isn't different from this for loop in terms of functionality.
I would however compare these two which one is simpler.
I think that's Florencia is very much simpler than the previous for loop above.
What do think okay by the way these variables commonly used.
Let me show you.
If I declare these variables out of the table look like this.
Then instead of using the short declaration I can use an assignment here like this.
This way the Range class you use these variables instead.
So what the benefit of this for example you can continue to use them after the look and the Range class
will keep them set up to their last value.
Let me print Damier right after the look.
Bus value Y And We person D person to I-we OK.
Now son it's as you can see go pre-NST the last value of the index and the value variable.
So if you need to reuse those variables you can do it like this.
All right.
Now let's take a look at Tom Florian's glassworks in the two
this highlighted part is called the range class as you can see it takes a slice and it returns to Elyas
from it one by one and it updates stamp on each step of the loop.
Escondida this part is totally the same with an ordinary four statements.
Nothing interesting to see here.
So let's continue.
This is the next RAIB.
It starts from zero and it will keep increasing automatically until the loop acts and the loop and only
after it loops over all the items inside the human Sless you don't need that in this way.
You can't skip it by using our old friends blank identifier.
You just need to replace the index table.
Dave blank I identify.
That's it's
this word here is devaluate like the Knicks rable the valley rable is also optional on each loops that
range Clowes will assign the next value to this variable.
It looks like this.
Here we get assigned to Vallier from the first slice by using any next over.
This logic happens behind the scenes.
So you don't even need to know about it's if you only need the inexplainable the blank identifier can
be used in place of its value.
So it will keep the values actually you don't even need to use the block on in the fire.
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 who 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.
Always split the range you want to two terms the next the next and the residue from the human expression
for each items inside the slice.
Behind the scenes it looks like this.
Here it is signs and next value to an index table.
And it also signs the next failure from the word slice.
This part is the range expression.
This expression can be anything that returns an array or a slice or a stream.
So the interesting thing here is that you can arrange a restaurant as well because a string is actually
read only by slice.
We'll talk about it later.
All right.
That's all for now.
See in the next picture.
I.