const (
at = iota //0
b //1
c //2
d = "ha" //独立值,iota += 1
e //"ha" iota += 1
f = 100 //iota +=1
g //100 iota +=1
h = iota //7,恢复计数
i //8
)
println(at, b, c, d, e, f, g, h, i)
输出:
0 1 2 ha ha 100 100 7 8
例2:
const (
i1=1<<iota
j=3<<iota
k
l
)
println(i1,j,k,l)
atest := 1
var ptr* int
ptr = &atest
println(ptr)
3.条件判断
if else语句
授权例子!!!
var pa int
var pb int
println("请输入密码: \n")
fmt.Scan(&pa)
if pa == 123456 {
println("用于获取授权!")
println("请输入进门授权码: \n")
fmt.Scan(&pb)
if pb == 111 {
println("成功!!!")
} else {
println("失败!!!")
}
} else {
println("非法***!!!")
}
switch语句
println("请输入条件字符串:\n")
var ch string
fmt.Scan(&ch)
switch ch {
case "a":
println("输入的是a!\n")
case "b":
println("输入的是b!\n")
case "c":
println("输入的是c!\n")
default:
println("输入无效!\n")
}