官术网_书友最值得收藏!

for

The for loop has three components, and can be used just like a for loop in C or Java. Go has no while loop because the for loop serves the same purpose when used with a single condition. Refer to the following example for more clarity:

package main

import (
"fmt"
)

func main() {
// Basic for loop
for i := 0; i < 3; i++ {
fmt.Println("i:", i)
}

// For used as a while loop
n := 5
for n < 10 {
fmt.Println(n)
n++
}
}
主站蜘蛛池模板: 西乡县| 平果县| 南汇区| 万州区| 综艺| 宁晋县| 万安县| 黎川县| 永胜县| 吉木萨尔县| 石台县| 兴宁市| 定边县| 平定县| 察哈| 青铜峡市| 淳化县| 蒙自县| 革吉县| 大竹县| 三门峡市| 夹江县| 辽宁省| 宜都市| 新泰市| 兴安盟| 门头沟区| 陇川县| 淮滨县| 佛教| 申扎县| 延川县| 溆浦县| 平阳县| 敦化市| 福海县| 垣曲县| 日照市| 陵水| 邵武市| 巴南区|