From f5628468fa7083e2e2944999f2e20534dabe8812 Mon Sep 17 00:00:00 2001 From: hanfeng Date: Mon, 16 Nov 2015 08:46:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9iota=E9=80=92=E5=A2=9E?= =?UTF-8?q?=E6=8F=8F=E8=BF=B0=E9=94=99=E8=AF=AF=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E5=AE=9E=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zh/02.2.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/zh/02.2.md b/zh/02.2.md index 7a61472b..4bb4dcc4 100644 --- a/zh/02.2.md +++ b/zh/02.2.md @@ -229,7 +229,7 @@ Go内置有一个`error`类型,专门用来处理错误信息,Go的`package` ### iota枚举 -Go里面有一个关键字`iota`,这个关键字用来声明`enum`的时候采用,它默认开始值是0,每调用一次加1: +Go里面有一个关键字`iota`,这个关键字用来声明`enum`的时候采用,它默认开始值是0,const中每增加一行加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有一些简便的操作 * [目录]() * 上一章: [你好,Go](<02.1.md>) * 下一节: [流程和函数](<02.3.md>) + +