Merge pull request #782 from vCaesar/master

Fix #781 and other err
This commit is contained in:
astaxie
2017-01-23 20:47:21 +08:00
committed by GitHub

View File

@@ -251,26 +251,36 @@ Go内置有一个`error`类型专门用来处理错误信息Go的`package`
Go里面有一个关键字`iota`,这个关键字用来声明`enum`的时候采用它默认开始值是0const中每增加一行加1
```Go
const(
x = iota // x == 0
y = iota // y == 1
z = iota // z == 2
w // 常量声明省略值时默认和之前一个值的字面相同。这里隐式地说w = iota因此w == 3。其实上面y和z可同样不用"= iota"
package main
import (
"fmt"
)
const (
x = iota // x == 0
y = iota // y == 1
z = iota // z == 2
w // 常量声明省略值时默认和之前一个值的字面相同。这里隐式地说w = iota因此w == 3。其实上面y和z可同样不用"= iota"
)
const v = iota // 每遇到一个const关键字iota就会重置此时v == 0
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
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
const (
a = iota //a=0
b = "B"
c = iota //c=2
d, e, f = iota, iota, iota //d=3,e=3,f=3
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`。