Motyar

Freelance Web Developer

Mar 10, 2016

Foreach in Golang

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
}

Labels:


By :