「Go言語」const識別子iotaのサンプル

書式
iotaは、定数宣言(const)の内での既定された識別子です。
型なしの整数の連番を生成します。
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
package main
import "fmt"
func main() {
const (
a = iota //0
b //1
c //2
d = "test" //iota += 1
e //"test" iota += 1
f = 120 //iota +=1
g //100 iota +=1
h = iota //7
i //8
)
fmt.Println(a,b,c,d,e,f,g,h,i)
}
package main import "fmt" func main() { const ( a = iota //0 b //1 c //2 d = "test" //iota += 1 e //"test" iota += 1 f = 120 //iota +=1 g //100 iota +=1 h = iota //7 i //8 ) fmt.Println(a,b,c,d,e,f,g,h,i) }
package main

import "fmt"

func main() {
    const (
            a = iota   //0
            b          //1
            c          //2
            d = "test"   //iota += 1
            e          //"test"   iota += 1
            f = 120    //iota +=1
            g          //100  iota +=1
            h = iota   //7
            i          //8
    )
    fmt.Println(a,b,c,d,e,f,g,h,i)
}

実行結果
>go run test.go
0 1 2 test test 120 120 7 8

Go言語

Posted by arkgame