Skip to content

Commit 6a9d555

Browse files
authored
Merge pull request astaxie#782 from vCaesar/master
Fix astaxie#781 and other err
2 parents d3b18ad + 2501c57 commit 6a9d555

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

zh/02.2.md

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -251,26 +251,36 @@ Go内置有一个`error`类型,专门用来处理错误信息,Go的`package`
251251
Go里面有一个关键字`iota`,这个关键字用来声明`enum`的时候采用,它默认开始值是0,const中每增加一行加1:
252252
```Go
253253

254-
const(
255-
x = iota // x == 0
256-
y = iota // y == 1
257-
z = iota // z == 2
258-
w // 常量声明省略值时,默认和之前一个值的字面相同。这里隐式地说w = iota,因此w == 3。其实上面y和z可同样不用"= iota"
254+
package main
255+
256+
import (
257+
"fmt"
258+
)
259+
260+
const (
261+
x = iota // x == 0
262+
y = iota // y == 1
263+
z = iota // z == 2
264+
w // 常量声明省略值时,默认和之前一个值的字面相同。这里隐式地说w = iota,因此w == 3。其实上面y和z可同样不用"= iota"
259265
)
260266

261267
const v = iota // 每遇到一个const关键字,iota就会重置,此时v == 0
262268

263269
const (
264-
e, f, g = iota, iota, iota //e=0,f=0,g=0 iota在同一行值相同
270+
h, i, j = iota, iota, iota //h=0,i=0,j=0 iota在同一行值相同
271+
)
272+
273+
const (
274+
a = iota //a=0
275+
b = "B"
276+
c = iota //c=2
277+
d, e, f = iota, iota, iota //d=3,e=3,f=3
278+
g = iota //g = 4
265279
)
266280

267-
const
268-
a = iota a=0
269-
b = "B"
270-
c = iota //c=2
271-
d,e,f = iota,iota,iota //d=3,e=3,f=3
272-
g //g = 4
273-
281+
func main() {
282+
fmt.Println(a, b, c, d, e, f, g, h, i, j, x, y, z, w, v)
283+
}
274284
```
275285
>除非被显式设置为其它值或`iota`,每个`const`分组的第一个常量被默认设置为它的0值,第二及后续的常量被默认设置为它前面那个常量的值,如果前面那个常量的值是`iota`,则它也被设置为`iota`
276286

0 commit comments

Comments
 (0)