Foreach in Golang ( golang foreach )

Sorry there is no foreach in Golang!

But using a for statement with range clause we can iterate through all entries of an array, slice, string or map, or values received on a channel.

for index,element := range someSlice { 
// index is the index where we are // element is the element from someSlice for where we are
}

You can simply ignore the index using _ like:-

for _,element := range someSlice { 
// element is the element from someSlice for where we are
}

By : Motyar+ @motyar


Originally published at motyar.blogspot.in.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.