- iota标识
- 每行单个iota
- 每行多个iota
iota是Golang中提供的一个简化常量和枚举编程的标识符。 iota标识
iota常用于const表达式中,其值从0开始,每增加一行其值自增1:
- iota代表const声明块中的行索引(一行中多次引用iota,其值也是相同的);
- 第一个常量必须指定一个常量表达式,后续常量若没有表达式,则继承上一行的;
当常量没有对应表达式时,会继承上一行的:
- second继承first的iota,为1;
- forth继承third的=10,为10;
- six继承five的iota表达式,为15;
如(10,five为4*3, six为5*3):
const ( first = iota second third = 10 forth five = iota * 3 six ) // 0 1 10 10 12 15每行多个iota
每行有多个iota,同一行中的iota值是相同的;此时后续各行也要有相同数量的const常量值定义
const ( bit0, mask0 = 1 << iota, 1<



