In Go, [n]T is an array of n values of type T; for example var a [10]int is ten integers laid out in memory. Searches such as golang iterate over array, golang array loop, golang for loop array, go iterate over array, golang loop through array, golang iterate array, go loop through array, golang loop over array, iterate over array golang, and go loop over array all map to the same two patterns: a for with range, or a classic index loop with len. This tutorial shows both on [5]string and [5]int arrays. For general loop syntax, see the for loop in Go guide.
Tested with Go 1.24 on Linux.
Range: golang array loop with index and value
The range keyword walks the array from index 0 through len(arr)-1. Each iteration gives you the index and a copy of the element (for small types like int or string that copy is cheap).
package main
import "fmt"
func main() {
strArr := [5]string{"Ana", "Bob", "Clair", "Daniel", "East"}
fmt.Println("String array:")
for index, element := range strArr {
fmt.Println("At index", index, "element is", element)
}
strInt := [5]int{5, 15, 36, 42, 69}
fmt.Println("Int array:")
for index, element := range strInt {
fmt.Println("At index", index, "element is", element)
}
}Running the program prints each String array: line with index and name, then each Int array: line with index and number.
Loop over values only (omit the index)
If you only need each element, use the blank identifier _ for the index:
package main
import "fmt"
func main() {
strArr := [5]string{"Ana", "Bob", "Clair", "Daniel", "East"}
fmt.Println("String array:")
for _, element := range strArr {
fmt.Println(element)
}
}That prints the five names one per line after the header.
Index loop: golang for loop array with len
The same walk uses a counter and len(arr) (arrays are always fixed length, so len is a constant at compile time for array types):
package main
import "fmt"
func main() {
strArr := [5]string{"Ana", "Bob", "Clair", "Daniel", "East"}
fmt.Println("String array:")
for i := 0; i < len(strArr); i++ {
fmt.Println("At index", i, "element is", strArr[i])
}
strInt := [5]int{5, 15, 36, 42, 69}
fmt.Println("Int array:")
for i := 0; i < len(strInt); i++ {
fmt.Println("At index", i, "element is", strInt[i])
}
}The observable output matches the range version above. Use this style when you need the index arithmetic explicitly or when stepping multiple arrays together with one i.
Arrays vs slices (one line)
[5]int and []int both support range and len, but an array’s length is part of its type; a slice is a descriptor over some backing array. For append and growth patterns, read a slice-focused article; for golang loop over array on a fixed [n]T, the loops here are all you need.
Summary
Golang iterate over array and go loop over array boil down to for i, v := range arr or for i := 0; i < len(arr); i++ with arr[i]. Golang array loop code almost always uses range for clarity; golang for loop array with len stays useful when the index drives the logic. Dropping the index with _ gives a clean golang loop through array over values only.
References
- The Go Programming Language Specification: For statements with range clause
- For loops in Go (tutorial)
- Stack Overflow: iterate over an array of a custom type in Go
- Stack Overflow: iterate two arrays or slices with one range

