package main
import (
"fmt"
"time"
)
/*有限次循环*/
/*func main23(){*/
/* for i := 1; i <=11; i++ {
fmt.Println(i)*/
/* for i :=10; i > 0; i-- {
fmt.Println(i)
}*/
/* for i :=2; i < 12; i+=2 {
fmt.Println(i)
}*/
/* for i :=3; i < 12; i+=2 {
fmt.Println(i)
}*/
/* for i :=9; i > 0; i-=2 {
fmt.Println(i)
}*/
/*无限次循环*/
/* func main() {
for {
fmt.Println("我爱撸代码")
time.Sleep(1 * time.Second)
}
}*/
/*退出循环*/
/*func main23() {
var count = 0
for {
if count % 2 == 1{
fmt.Println("我爱撸代码")
} else{
fmt.Println("我爱撩妹")
}
}
fmt.Println("我是帅哥")
count ++
time.Sleep(500 * time.Millisecond)
if count >=5{
//跳出循环
break
}
}
fmt.Println("game over")
}*/
/*每天撸代码,逢五就休息*/
func main() {
var count = 0
for {
count ++
if count % 5 ==0 {
/*忽略本次循环进入下一次循环*/
continue
}
/*正常的循环逻辑*/
fmt.Println("我爱写代码",count)
time.Sleep(500 * time.Millisecond)
count ++
if count > 20 {
//跳出循环
break
}
fmt.Println("GAME OVER")
}
}
网友评论