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

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++
}
}
主站蜘蛛池模板: 鄯善县| 西城区| 沽源县| 峡江县| 万全县| 门头沟区| 丹棱县| 南充市| 诸城市| 曲沃县| 读书| 大邑县| 永康市| 兰溪市| 新建县| 玛纳斯县| 甘洛县| 乌鲁木齐市| 罗甸县| 平邑县| 湖南省| 久治县| 林西县| 巩义市| 台山市| 灵武市| 福安市| 华亭县| 普兰店市| 九龙坡区| 交口县| 寿阳县| 遂平县| 安化县| 安多县| 临海市| 蒙城县| 昔阳县| 新营市| 黔南| 伊金霍洛旗|