12_Go基础(iota)

package main

import "fmt"

const (
    a1 = 100
    a2
    a3
)

// const 中每声明一行,iota + 1
const (
    b1 = iota
    c1 = 100
    b2 = iota
    b3
)

const (
    d1, d2 = iota + 1, iota + 2 // 只有一行,iota 不自增
    d3, d4 = iota + 1, iota + 2 // 增加一行,iota + 1
)

func main() {
    fmt.Println(a3, b3)         // 100 3
    fmt.Println(d1, d2, d3, d4) // 1 2 2 3
}
原文地址:https://www.cnblogs.com/luwei0915/p/15357587.html