How do constants and iota work in Go?

Answer

Constants in Go are declared with const and must have a value known at compile time: const Pi = 3.14159. The iota identifier is a special counter used in const blocks that starts at 0 and increments by 1 for each constant in the block. It enables elegant enumerations: const (Sunday = iota; Monday; Tuesday ...). Combined with expressions, iota can create bitflag constants (1 << iota) or skip values. Each new const block resets iota to zero.