if语句
在go语言中if语句的写法是比较简单的,也是很常见的
func main() {
a := true
if a {
fmt.Println("a is true")
}
}
if else 语句
func main() {
a := true
if !a {
fmt.Println("a is true")
} else {
fmt.Println("a is false")
}
}
else if语句
func main() {
a := 2
if a == 1 {
fmt.Println("a is 1")
} else if a == 2 {
fmt.Println("a is 2")
}
}
如果你有任何语言的编程基础,这章节就非常简单,除了写法上略有区别,逻辑上是完全一样的