Contents
8. Forloop-循环语句¶
Go只有一种类型的循环,那就是for循环。
8.1. Python¶
#!/usr/bin/env python
# -*- coding:utf8 -*-
# auther; 18793
# Date:2020/4/21 13:50
# filename: sample1.py
i = 1
while i <= 10:
print(i)
i += 1
# ...or...
for i in range(1, 11):
print(i)
8.2. Go¶
package main
import "fmt"
func main() {
i := 1
for i <= 10 {
fmt.Println(i)
i += 1
}
// same thing more but more convenient
for i := 1; i <= 10; i++ {
fmt.Println(i)
}
}