Newer
Older
01_hello / iota.go
yhornisse on 22 Sep 2021 585 bytes add iota sample
package main

import "fmt"

// enum的な
type Weekday int64
const (
	Sunday Weekday = iota // 0はじまり
	Monday // 1
	Tuesday // 2
	Wednesday // 3
	Thursday // 4
	Friday // 5
	Saturday // 6
)

const (
	_ = 1 << (10 * iota) // 1 << (10 * 0)
	KiB // 1 << (10 * 1)
	MiB // 1 << (10 * 2)
	GiB // 1 << (10 * 3)
	TiB // 1 << (10 * 4)
)

func main() {
	// 0 1 2 3 4 5 6
	fmt.Printf("%d %d %d %d %d %d %d\n",
		Sunday,
		Monday,
		Tuesday,
		Wednesday,
		Thursday,
		Friday,
		Saturday)
	// 1024 1048576 1073741824 1099511627776
	fmt.Printf("%d %d %d %d\n",
		KiB,
		MiB,
		GiB,
		TiB)
}