Sobes.tech
Junior — Middle

How to perform a sequential traversal of array elements?

sobes.tech AI

Answer from AI

In Go, to iterate over array elements sequentially, a for loop with an index or a for range construct is used.

Example using for range:

arr := []int{1, 2, 3, 4, 5}
for index, value := range arr {
    fmt.Printf("Index: %d, Value: %d\n", index, value)
}

If the index is not needed, it can be omitted:

for _, value := range arr {
    fmt.Println(value)
}
How to perform a sequential traversal of array… - sobes.tech