Why iota logic mismatch


const (
        zero myConst = iota
        one
        three = iota + 1
        foure
        five = iota + 1
)

func testIota() {
        // 3 4 5 why not 3 4 6
        fmt.Println(three, foure, five)
}```
 why output is "3 4 5" not "3 4 6" executed in go version go1.13.10 linux/amd64
1 Like

iota ist the “index” in the const. It monotically counts from 0 to positive infinity.

With an assignment in a const block that uses iota you don’t change any iota itself, only the formula how the consts value is calculated. So in case of five you basically say, that go shall calculate the value the same way as it already did, by adding 1 to iota, which at that place is 4.

1 Like

got it, thanks a lot!