This commit is contained in:
Unknown
2014-06-16 09:58:16 -04:00
parent 2ee37bd330
commit 311a81f81c
3 changed files with 89 additions and 13 deletions

View File

@@ -9,7 +9,7 @@
## 翻译进度 ## 翻译进度
5.4 [for 结构](eBook/05.4.md) 5.5 [Break 与 continue](eBook/05.5.md)
## 支持本书 ## 支持本书

View File

@@ -1,18 +1,76 @@
## 啊哦,亲,你看得也太快了。。。还没翻译完呢 0 0 # 5.5 Break 与 continue
要不等到 **2014 年 6 月 10 日** 再来看看吧~~ 您可以使用 break 语句重写 for2.go 的代码:
这里还有一些其它的学习资源噢~ Listing 5.10 [for3.go](examples/chapter_5/for3.go)
- [《Go编程基础》](https://github.com/Unknwon/go-fundamental-programming) ```
- [《Go Web编程》](https://github.com/astaxie/build-web-application-with-golang) for {
- [《Go名库讲解》](https://github.com/Unknwon/go-rock-libraries-showcases) i = i - 1
fmt.Printf(“The variable i is now: %d\n”, i)
if i < 0 {
break
}
}
```
神马?你说你不想学习?那好吧,去逛逛看看行情也行~ 因此每次迭代都会对条件进行检查i < 0以此判断是否需要停止循环如果退出条件满足则使用 break 语句退出循环
- [Go Walker](https://gowalker.org) **Go 项目 API 文档在线浏览工具** 一个 break 的作用范围为该语句出现后的最内部的结构它可以被用于任何形式的 for 循环计数器条件判断等)。但在 switch select 语句中详见第 13 break 语句的作用结果是跳过整个代码块执行后续的代码
- [Go 中国社区](http://bbs.go-china.org)
- [Go语言学习园地](http://studygolang.com/)
- [Golang中国](http://golangtc.com)
# 5.5 Break 与 continue 下面的示例中包含了嵌套的循环体for4.gobreak 只会退出最内层的循环
Listing 5.11 [for4.go](examples/chapter_5/for4.go)
```
package main
func main() {
for i:=0; i<3; i++ {
for j:=0; j<10; j++ {
if j>5 {
break
}
print(j)
}
print(" ")
}
}
```
输出
012345 012345 012345
关键字 continue 忽略剩余的循环体而直接进入下一次循环的过程但不是无条件执行下一次循环执行之前依旧需要满足循环的判断条件
Listing 5.12 [for5.go](examples/chapter_5/for5.go)
```
package main
func main() {
for i := 0; i < 10; i++ {
if i == 5 {
continue
}
print(i)
print(" ")
}
}
```
输出
```
0 1 2 3 4 6 7 8 9
5 is skipped
```
关键字 continue 只能被用于 for 循环中
## 链接
- [目录](directory.md)
- 上一节[for 结构](05.4.md)
- 下一节[标签与 goto](05.6.md)

18
eBook/05.6.md Normal file
View File

@@ -0,0 +1,18 @@
## 啊哦,亲,你看得也太快了。。。还没翻译完呢 0 0
要不等到 **2014 年 6 月 18 日** 再来看看吧~~
这里还有一些其它的学习资源噢~
- [《Go编程基础》](https://github.com/Unknwon/go-fundamental-programming)
- [《Go Web编程》](https://github.com/astaxie/build-web-application-with-golang)
- [《Go名库讲解》](https://github.com/Unknwon/go-rock-libraries-showcases)
神马?你说你不想学习?那好吧,去逛逛看看行情也行~
- [Go Walker](https://gowalker.org) **Go 项目 API 文档在线浏览工具**
- [Go 中国社区](http://bbs.go-china.org)
- [Go语言学习园地](http://studygolang.com/)
- [Golang中国](http://golangtc.com)
# 5.6 标签与 goto