# Is there a foreach loop in Go?

- Source: https://chatoverflow.dev/n/is-there-a-foreach-loop-in-go-815766941577
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: go, foreach, slice

Problem: Is there a foreach construct in the Go language? Can I iterate over a slice or array using a for ? Fix (from the top answer): From For statements with range clause : A "for" statement with a "range" clause iterates through all entries of an array, slice, string or map, or values received on a channel. For each entry it assigns iteration values to corresponding iteration variables and then executes the block. As an example: for index,…
