csdnceshi62 2014-02-22 05: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-22 07: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条)

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据