Skip to content

Commit 71d146b

Browse files
committed
Merge pull request astaxie#558 from bjhanfeng/master
修改iota递增描述错误,添加相关实例
2 parents c9d940d + f562846 commit 71d146b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

zh/02.2.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ Go内置有一个`error`类型,专门用来处理错误信息,Go的`package`
229229

230230
### iota枚举
231231

232-
Go里面有一个关键字`iota`,这个关键字用来声明`enum`的时候采用,它默认开始值是0,每调用一次加1
232+
Go里面有一个关键字`iota`,这个关键字用来声明`enum`的时候采用,它默认开始值是0,const中每增加一行加1
233233

234234
const(
235235
x = iota // x == 0
@@ -243,6 +243,14 @@ Go里面有一个关键字`iota`,这个关键字用来声明`enum`的时候采
243243
const (
244244
e, f, g = iota, iota, iota //e=0,f=0,g=0 iota在同一行值相同
245245
)
246+
247+
const (
248+
a = iota a=0
249+
b = "B"
250+
c = iota //c=2
251+
d,e,f = iota,iota,iota //d=3,e=3,f=3
252+
g //g = 4
253+
246254

247255
>除非被显式设置为其它值或`iota`,每个`const`分组的第一个常量被默认设置为它的0值,第二及后续的常量被默认设置为它前面那个常量的值,如果前面那个常量的值是`iota`,则它也被设置为`iota`
248256
@@ -482,3 +490,5 @@ slice有一些简便的操作
482490
* [目录](<preface.md>)
483491
* 上一章: [你好,Go](<02.1.md>)
484492
* 下一节: [流程和函数](<02.3.md>)
493+
494+

0 commit comments

Comments
 (0)