A common loop pattern accumulates values:
nums := []int{1, 2, 3, 4, 5}
sum := 0
for _, n := range nums {
sum += n
}
fmt.Println(sum) // 15
Initialize an accumulator before the loop, update it inside, and use the result after. This pattern works for sums, products, string building, and more.