golang --iota 用法

package main

import "fmt"

func main() {
	const (
		a = iota //0
		b        //1
		c        //2
		d = "ha" //独立值,iota += 1
		e        //"ha"   iota += 1
		f = 100  //iota +=1
		g        //100  iota +=1
		h = iota //7,恢复计数
		i        //8
	)
	fmt.Println(a, b, c, d, e, f, g, h, i)
}

 输出结果:

0 1 2 ha ha 100 100 7 8

posted on 2019-07-04 14:19  清明-心若淡定  阅读(543)  评论(0编辑  收藏  举报