mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 00:43:26 +08:00
5.4.2
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
## 啊哦,亲,你看得也太快了。。。还没翻译完呢 0 0
|
||||
|
||||
要不等到 **2014 年 6 月 6 日** 再来看看吧~~
|
||||
要不等到 **2014 年 6 月 7 日** 再来看看吧~~
|
||||
|
||||
这里还有一些其它的学习资源噢~
|
||||
|
||||
@@ -202,3 +202,37 @@ GGGGGG
|
||||
|
||||
## 5.4.2 基于条件判断的迭代
|
||||
|
||||
for 结构的第二种形式是没有头部的条件判断迭代(类似其它语言中的 while 循环),基本形式为:`for 条件语句 {}`。
|
||||
|
||||
您也可以认为这是没有初始化语句和修饰语句的 for 结构,因此 `;;` 便是多余的了。
|
||||
|
||||
Listing 5.8 [for2.go](examples/chapter_5/for2.go):
|
||||
|
||||
```
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
var i int = 5
|
||||
|
||||
for i >= 0 {
|
||||
i = i - 1
|
||||
fmt.Printf("The variable i is now: %d\n", i)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
输出:
|
||||
|
||||
```
|
||||
The variable i is now: 4
|
||||
The variable i is now: 3
|
||||
The variable i is now: 2
|
||||
The variable i is now: 1
|
||||
The variable i is now: 0
|
||||
The variable i is now: -1
|
||||
```
|
||||
|
||||
## 5.4.3 无限循环
|
||||
|
||||
|
Reference in New Issue
Block a user