goconstantsiota

Is there any way to increase single group of const by a fixed number rather than 1?


I have a single group of constant:

const (
    a = 100
    b = 200
    c = 300
)

I was wondering if there is any way to use iota keyword instead of assigning each value manually?

As described in the official reference, it is possible to use bitwise shift with iota to increase numbers, but I want to increase by a fixed number like 100 for example.


Solution

  • const (
        _ = iota * 100
        a
        b
        c
    )
    

    https://play.golang.org/p/V-2Uv9JPj6g