Go 笔记 - 1-11 iota枚举
2018-10-11 17:35:46    169    0    0
akiragatsu

package main

  1. import "fmt"
  2. func main() {
  3. //1、iota常量自动生成器 每隔一行 自动累加1
  4. //2、iota给常量赋值
  5. const (
  6. a = iota //0
  7. b = iota //1
  8. c = iota //2
  9. )
  10. fmt.Printf("a = %d,b = %d,c = %d\n", a, b, c)
  11. //3 iota 遇到const 就会重置为0
  12. const d = iota
  13. fmt.Printf("d = %d\n", d)
  14. //可以只写一个iota
  15. const (
  16. a1 = iota //0
  17. b1 //1
  18. c1 //2
  19. )
  20. fmt.Printf("a1 = %d,b1 = %d,c1 = %d\n", a1, b1, c1)
  21. //5 如果在同一行 值都一样
  22. const (
  23. i = iota
  24. j1, j2, j3 = iota, iota, iota
  25. k = iota
  26. )
  27. fmt.Printf("i = %d,j1 = %d,j2 = %d,j3 = %d\n,k = %d\n", i, j1, j2, j3, k)
  28. }

Pre: Go 笔记 - 1-12 类型的分类

Next: Go 笔记 - 1-10 多个变量或常量定义

169
Sign in to leave a comment.
No Leanote account? Sign up now.
0 comments
Table of content