csdnceshi62 2014-02-21 21:39 采纳率: 100%
浏览 257
已采纳

在 Golang 有没有一种方法可以迭代一个整数范围?

Golang's range can iterate over maps and slices, but I was wondering if there is a way to iterate over a range of numbers, something like this

for i := range [1..10] {
    fmt.Println(i)
}

or is there a way to represent range of integers in Go like how ruby does?

转载于:https://stackoverflow.com/questions/21950244/is-there-a-way-to-iterate-over-a-range-of-integers-in-golang

  • 写回答

8条回答 默认 最新

  • MAO-EYE 2014-02-21 23:15
    关注

    You can, and should, just write a for loop. Simple, obvious code is the Go way.

    for i := 1; i <= 10; i++ {
        fmt.Println(i)
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(7条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部