GO語言中,有三種,能夠看到在GO中浮點數能夠做爲循環變量的。python
func main() { i := 10 for { i += 1 if i > 18 { break } } for i := 0.1; i <= 10; i += 0.2 { fmt.Println(i) } for i := 10; i >= 0; i-- { fmt.Println(i) } fmt.Println("over") }
而python中,只能自定義一個函數做爲浮點數的變量遞增。函數
for i in range (10): print(i) for i in range(1,10,2): print(i) def progression(start, length,step): for i in range(length): yield start + i * step for i in progression(1,10,0.8): print(i) a=0 while a<10: a+=1 print(a)