rand.Seed(time.Now().UnixNano())
var n = rand.Int()
if n%2 == 0 {
fmt.Println(n, "是一个偶数")
} else {
fmt.Println(n, "是一个奇数")
}
if a := rand.Int(); a%2 != 0 {
fmt.Println(a, "是一个奇数")
} else {
fmt.Println(a, "是一个偶数")
}
for i := 0; i < 10; i++ {
if i == 4 {
continue
}
fmt.Println(i)
}
for i := 0; i < 10; i++ {
if i == 4 {
break
}
fmt.Println(i)
}
y := rand.Intn(100) % 5
fmt.Println(y)
switch y {
case 0, 1:
fmt.Println("0 1y =", y)
fallthrough
case 2, 3:
fmt.Println("2 3y =", y)
fallthrough
case 4, 5:
fmt.Println("4 5y =", y)
fallthrough
default:
fmt.Println("default y =", y)
}
package main
import "fmt"
func main() {
i := 0
Next: // 跳转标签声明
fmt.Println(i)
i++
if i < 5 {
goto Next // 跳转
}
}