Fix #781 and other err
This commit is contained in:
24
zh/02.2.md
24
zh/02.2.md
@@ -251,7 +251,13 @@ Go内置有一个`error`类型,专门用来处理错误信息,Go的`package`
|
|||||||
Go里面有一个关键字`iota`,这个关键字用来声明`enum`的时候采用,它默认开始值是0,const中每增加一行加1:
|
Go里面有一个关键字`iota`,这个关键字用来声明`enum`的时候采用,它默认开始值是0,const中每增加一行加1:
|
||||||
```Go
|
```Go
|
||||||
|
|
||||||
const(
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
x = iota // x == 0
|
x = iota // x == 0
|
||||||
y = iota // y == 1
|
y = iota // y == 1
|
||||||
z = iota // z == 2
|
z = iota // z == 2
|
||||||
@@ -261,16 +267,20 @@ Go里面有一个关键字`iota`,这个关键字用来声明`enum`的时候采
|
|||||||
const v = iota // 每遇到一个const关键字,iota就会重置,此时v == 0
|
const v = iota // 每遇到一个const关键字,iota就会重置,此时v == 0
|
||||||
|
|
||||||
const (
|
const (
|
||||||
e, f, g = iota, iota, iota //e=0,f=0,g=0 iota在同一行值相同
|
h, i, j = iota, iota, iota //h=0,i=0,j=0 iota在同一行值相同
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
a = iota a=0
|
a = iota //a=0
|
||||||
b = "B"
|
b = "B"
|
||||||
c = iota //c=2
|
c = iota //c=2
|
||||||
d,e,f = iota,iota,iota //d=3,e=3,f=3
|
d, e, f = iota, iota, iota //d=3,e=3,f=3
|
||||||
g //g = 4
|
g = iota //g = 4
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Println(a, b, c, d, e, f, g, h, i, j, x, y, z, w, v)
|
||||||
|
}
|
||||||
```
|
```
|
||||||
>除非被显式设置为其它值或`iota`,每个`const`分组的第一个常量被默认设置为它的0值,第二及后续的常量被默认设置为它前面那个常量的值,如果前面那个常量的值是`iota`,则它也被设置为`iota`。
|
>除非被显式设置为其它值或`iota`,每个`const`分组的第一个常量被默认设置为它的0值,第二及后续的常量被默认设置为它前面那个常量的值,如果前面那个常量的值是`iota`,则它也被设置为`iota`。
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user