diff --git a/doc/spec-mini.md b/doc/spec-mini.md index 06e4ab6e0..5de798f4e 100644 --- a/doc/spec-mini.md +++ b/doc/spec-mini.md @@ -1848,7 +1848,44 @@ const ( ### Iota -TODO +Within a [constant declaration](#constant-declarations), the predeclared identifier iota represents successive untyped integer [constants](#constants). Its value is the index of the respective [ConstSpec]() in that constant declaration, starting at zero. It can be used to construct a set of related constants: + +```go +const ( + c0 = iota // c0 == 0 + c1 = iota // c1 == 1 + c2 = iota // c2 == 2 +) + +const ( + a = 1 << iota // a == 1 (iota == 0) + b = 1 << iota // b == 2 (iota == 1) + c = 3 // c == 3 (iota == 2, unused) + d = 1 << iota // d == 8 (iota == 3) +) + +const ( + u = iota * 42 // u == 0 (untyped integer constant) + v float64 = iota * 42 // v == 42.0 (float64 constant) + w = iota * 42 // w == 84 (untyped integer constant) +) + +const x = iota // x == 0 +const y = iota // y == 0 +``` + +By definition, multiple uses of iota in the same ConstSpec all have the same value: + +```go +const ( + bit0, mask0 = 1 << iota, 1<