iota

Tutorial: Go初级 Category: Go Published: 2026-04-07 13:58:26 Views: 21 Likes: 0 Comments: 0
package main

import (
    "fmt"
)


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(b1, c1, b2, b3) // 0 100  2 3
    fmt.Println(d1, d2, d3, d4) // 1 2 2 3
}
Prev: 函数 Next: binary