go语言练习:条件语句和循环语句

时间:2024-09-12 12:33:38

1.for循环+if条件语句简单例子:

package main

import "fmt"

func main() {
var a int
for a = 0; a <= 2; a++ {
if a > 1 {
fmt.Println("a>1")
} else if a == 1 {
fmt.Println("a=1")
} else {
fmt.Println("a<1")
}
}
}

2.switch简单例子:

package main

import "fmt"

func main() {
var a int
a = 0
switch a {
case 0:
fmt.Println("hello")
case 1:
fmt.Println("hello1")
default:
fmt.Println("hello2")
}
}