修改iota递增描述错误,添加相关实例

This commit is contained in:
hanfeng
2015-11-16 08:46:36 +08:00
parent 80c5211df4
commit ab5ad9ab5b

View File

@@ -229,7 +229,7 @@ Go内置有一个`error`类型专门用来处理错误信息Go的`package`
### iota枚举
Go里面有一个关键字`iota`,这个关键字用来声明`enum`的时候采用它默认开始值是0每调用一次加1
Go里面有一个关键字`iota`,这个关键字用来声明`enum`的时候采用它默认开始值是0const中每增加一行加1
const(
x = iota // x == 0
@@ -243,6 +243,14 @@ Go里面有一个关键字`iota`,这个关键字用来声明`enum`的时候采
const (
e, f, g = iota, iota, iota //e=0,f=0,g=0 iota在同一行值相同
)
const
a = iota a=0
b = "B"
c = iota //c=2
d,e,f = iota,iota,iota //d=3,e=3,f=3
g //g = 4
>除非被显式设置为其它值或`iota`,每个`const`分组的第一个常量被默认设置为它的0值第二及后续的常量被默认设置为它前面那个常量的值如果前面那个常量的值是`iota`,则它也被设置为`iota`。
@@ -482,3 +490,5 @@ slice有一些简便的操作
* [目录](<preface.md>)
* 上一章: [你好,Go](<02.1.md>)
* 下一节: [流程和函数](<02.3.md>)