package main import "fmt" func main() { // for循环,输出:0123456789 i := 0 for i < 10 { fmt.Print(i) i++ } }
普通for循环2:
package main import "fmt" func main() { // for循环,输出:0123456789 for i := 0; i < 10; i++ { fmt.Print(i) } }
死循环:
package main import "fmt" func main() { // 死循环 // for{} }
类似while循环:
package main import "fmt" func main() { //类似while循环,输出:-1 i := 0 for { i-- fmt.Print(i) if i <= 0 { break } } }