5.Go by Example: For
来源:互联网 发布:java封装类例子 编辑:程序博客网 时间:2024/05/22 06:32
Go by Example: For
for is Go’s only looping construct. Here are three basic types of for loops.
The most basic type, with a single condition.
A classic initial/condition/after for loop.
运行结果
go run for.go
1
2
3
7
8
9
10
for is Go’s only looping construct. Here are three basic types of for loops.
The most basic type, with a single condition.
A classic initial/condition/after for loop.
for without a condition will loop repeatedly until you break out of the loop or return from the enclosing function.
package mainimport "fmt"func main() { i := 1 for i <= 3 { fmt.Println(i) i = i + 1 } for j := 7; j <= 9; j++ { fmt.Println(j) } for { fmt.Println("loop") break }}
译:
for 关键字是在go语言中唯一一个循环结构,下面的就是for循环的三个基本类型结构
最基本的是一个单条件
一个是 初始值/条件/然后的自身处理条件对于 for循环
for 循环对于没有条件的将会一直循环直到break出循环,或者在外围函数返回
package mainimport "fmt"func main() {i := 1for i <= 3 { //相当于while循环fmt.Println(i)i = i + 1}for j := 7; j <= 10; j++ { //传统的for循环fmt.Println(j)}for { //类似于 do。。。while循环fmt.Println("loop")break}}
运行结果
go run for.go
1
2
3
7
8
9
10
loop
原文地址
0 0
- 5.Go by Example: For
- Go by Example: For
- Go by Example: Values
- Go by Example: Variables
- Go by Example: Constants
- Go by Example: Switch
- Go by Example: Arrays
- Go by Example: Slices
- Go by Example: Maps
- Go by Example: Range
- Go by Example: Functions
- Go by Example: Closures
- Go by Example: Recursion
- Go by Example: Pointers
- Go by Example: JSON
- 2.Go by Example: Values
- 3.Go by Example: Variables
- 4.Go by Example: Constants
- Unity3d脚本周期
- Sql injection 教程,包括盲注 (英语版+翻譯)
- HDU4289(最大流)(dinic算法+拆点)
- java注解
- NYOJ 189 兔子的烦恼(一)
- 5.Go by Example: For
- U盘原版安装windows 2003(32/64位)
- 情人节ios小程序
- C++中placement new操作符(经典)
- IOS多线程
- BeanFactory与ApplicationContext【Spring】
- 一段失败的代码 inotify的使用
- 支持老版本IE的3种解决方案
- 八皇后问题