指针
Go 语言中,对于指针有一些特殊约束:
1. 不在支持 “->” 符号,所有的指针使用“.” 来操作指针对象的成员变量
2. 指针的默认值为 “nil”
++ 与 -- 作为语句而非表达式
语句必须单独存在与一行,不能放在 “=” 右边
var a = 1 a++
Go 语句
条件判断: if
循环语句 :for
switch 语句
func main() { // fmt.Println(e) // fmt.Println(f) // fmt.Println(^i) // fmt.Println(KB)
a := 2 switch {
// switch a:=2; { // 也可以定义局部变量a, 他的左右范围为 switch 语句的开始到结束 case a > 0: fmt.Println("a>0") fallthrough case a >= 1: fmt.Println("a>=1") default: fmt.Println("ohter result a ") } } //output a>0 a>=1
跳转语句与标签的组合应用
跳转语句有: break / continue / goto
标签关键字: LABEL
func main() { LABEL: for { for i := 0; i < 10; i++ { break LABEL fmt.Println(i) } } fmt.Println("Loop done!") } //output Loop done!